Commit 06896335 authored by larowlan's avatar larowlan

Reset to c914f043

parent 93824c26
<?php
/**
* @file
* Installs default content on the behalf of modules at time of install.
*/
/**
* Implements hook_install().
* check all existing modules for imported content()
*/
function default_content_install() {
foreach (\Drupal::moduleHandler()->getModuleList() as $module => $null) {
\Drupal::service('default_content.manager')->importContent($module);
}
}
<?php
/**
* @file
* Installs default content on the behalf of modules at time of install.
*/
/**
* Implements hook_modules_installed().
*/
......
......@@ -58,9 +58,10 @@ class DefaultContentManager implements DefaultContentManagerInterface {
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
protected $entityManager;
/**
<<<<<<< HEAD
* The entity repository.
*
* @var \Drupal\Core\Entity\EntityRepositoryInterface
......@@ -68,6 +69,8 @@ class DefaultContentManager implements DefaultContentManagerInterface {
protected $entityRepository;
/**
=======
>>>>>>> origin/8.x-1.x
* The module handler.
*
* @var \Drupal\Core\Extension\ModuleHandlerInterface
......@@ -125,7 +128,7 @@ class DefaultContentManager implements DefaultContentManagerInterface {
* The rest resource plugin manager.
* @param \Drupal\Core\Session|AccountInterface $current_user
* The current user.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_manager
* The entity type manager service.
* @param \Drupal\Core\Entity\EntityRepositoryInterface $entity_repository
* The entity repository service.
......@@ -138,10 +141,10 @@ class DefaultContentManager implements DefaultContentManagerInterface {
* @param \Drupal\Core\Extension\InfoParserInterface $info_parser
* The info file parser.
*/
public function __construct(Serializer $serializer, ResourcePluginManager $resource_plugin_manager, AccountInterface $current_user, EntityTypeManagerInterface $entity_type_manager, EntityRepositoryInterface $entity_repository, LinkManagerInterface $link_manager, EventDispatcherInterface $event_dispatcher, ModuleHandlerInterface $module_handler, InfoParserInterface $info_parser) {
public function __construct(Serializer $serializer, ResourcePluginManager $resource_plugin_manager, AccountInterface $current_user, EntityTypeManagerInterface $entity_manager, EntityRepositoryInterface $entity_repository, LinkManagerInterface $link_manager, EventDispatcherInterface $event_dispatcher, ModuleHandlerInterface $module_handler, InfoParserInterface $info_parser) {
$this->serializer = $serializer;
$this->resourcePluginManager = $resource_plugin_manager;
$this->entityTypeManager = $entity_type_manager;
$this->entityManager = $entity_manager;
$this->entityRepository = $entity_repository;
$this->linkManager = $link_manager;
$this->eventDispatcher = $event_dispatcher;
......@@ -158,7 +161,7 @@ class DefaultContentManager implements DefaultContentManagerInterface {
if (file_exists($folder)) {
$file_map = array();
foreach ($this->entityTypeManager->getDefinitions() as $entity_type_id => $entity_type) {
foreach ($this->entityManager->getDefinitions() as $entity_type_id => $entity_type) {
$reflection = new \ReflectionClass($entity_type->getClass());
// We are only interested in importing content entities.
if ($reflection->implementsInterface('\Drupal\Core\Config\Entity\ConfigEntityInterface')) {
......@@ -223,10 +226,6 @@ class DefaultContentManager implements DefaultContentManagerInterface {
$contents = $this->parseFile($file);
$class = $definition['serialization_class'];
$entity = $this->serializer->deserialize($contents, $class, 'hal_json', array('request_method' => 'POST'));
if ($this->entityTypeManager->getStorage($entity_type_id)->loadByProperties(['uuid' => $entity->uuid()])) {
drupal_set_message(t('node @uuid already exists', ['@uuid' => $entity->uuid()]));
continue;
}
$entity->enforceIsNew(TRUE);
$entity->save();
$created[$entity->uuid()] = $entity;
......@@ -245,7 +244,7 @@ class DefaultContentManager implements DefaultContentManagerInterface {
* {@inheritdoc}
*/
public function exportContent($entity_type_id, $entity_id) {
$storage = $this->entityTypeManager->getStorage($entity_type_id);
$storage = $this->entityManager->getStorage($entity_type_id);
$entity = $storage->load($entity_id);
$this->linkManager->setLinkDomain(static::LINK_DOMAIN);
......@@ -261,7 +260,7 @@ class DefaultContentManager implements DefaultContentManagerInterface {
* {@inheritdoc}
*/
public function exportContentWithReferences($entity_type_id, $entity_id) {
$storage = $this->entityTypeManager->getStorage($entity_type_id);
$storage = $this->entityManager->getStorage($entity_type_id);
$entity = $storage->load($entity_id);
if (!$entity) {
......
<?php
/**
* @file
* Contains \Drupal\default_content\DefaultContentServiceProvider.
*/
namespace Drupal\default_content;
use Drupal\Core\DependencyInjection\ServiceProviderBase;
use Drupal\Core\DependencyInjection\ContainerBuilder;
/**
* A default content service provider.
*/
class DefaultContentServiceProvider extends ServiceProviderBase {
/**
* {@inheritdoc}
*/
public function alter(ContainerBuilder $container) {
$container
->getDefinition('rest.link_manager.type')
->setClass('Drupal\default_content\LinkManager\TypeLinkManager');
$container
->getDefinition('rest.link_manager.relation')
->setClass('Drupal\default_content\LinkManager\RelationLinkManager');
}
}
......@@ -36,7 +36,7 @@ class RelationLinkManager extends RestRelationLinkManager {
/**
* {@inheritdoc}
*/
public function getRelationUri($entity_type, $bundle, $field_name, $context = array()) {
public function getRelationUri($entity_type, $bundle, $field_name) {
// Make the base path refer to drupal.org.x`
return "http://drupal.org/rest/relation/$entity_type/$bundle/$field_name";
}
......@@ -44,7 +44,7 @@ class RelationLinkManager extends RestRelationLinkManager {
/**
* {@inheritdoc}
*/
protected function writeCache($context = []) {
protected function writeCache() {
$data = array();
foreach ($this->entityManager->getDefinitions() as $entity_type_id => $entity_type) {
......
......@@ -17,7 +17,7 @@ class TypeLinkManager extends RestTypeLinkManager {
/**
* {@inheritdoc}
*/
public function getTypeUri ($entity_type, $bundle, $context = array()) {
public function getTypeUri($entity_type, $bundle) {
// Make the base path refer to drupal.org.
return "http://drupal.org/rest/type/$entity_type/$bundle";
}
......
......@@ -7,6 +7,7 @@
namespace Drupal\default_content\Tests;
use Drupal\simpletest\WebTestBase;
use Drupal\taxonomy\Entity\Vocabulary;
/**
* Test import of default content.
......@@ -42,7 +43,7 @@ class DefaultContentTest extends WebTestBase {
$node = $this->drupalGetNodeByTitle('Imported node');
$this->assertEqual($node->body->value, 'Crikey it works!');
$this->assertEqual($node->getType(), 'page');
$terms = \Drupal::entityTypeManager()->getStorage('taxonomy_term')->loadMultiple();
$terms = \Drupal::entityManager()->getStorage('taxonomy_term')->loadMultiple();
$term = reset($terms);
$this->assertTrue(!empty($term));
$this->assertEqual($term->name->value, 'A tag');
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment