diff --git a/core/lib/Drupal/Core/Entity/EntityManager.php b/core/lib/Drupal/Core/Entity/EntityManager.php index bb9986b..316e0c6 100644 --- a/core/lib/Drupal/Core/Entity/EntityManager.php +++ b/core/lib/Drupal/Core/Entity/EntityManager.php @@ -171,7 +171,7 @@ public function hasController($entity_type, $controller_type) { */ public function getStorageController($entity_type) { if (!isset($this->controllers['storage'][$entity_type])) { - $definition = $this->getDefinition($entity_type); + $definition = $this->getEntityTypeForReal($entity_type); $class = $definition->getStorage(); if (in_array('Drupal\Core\Entity\EntityControllerInterface', class_implements($class))) { $controller = $class::createInstance($this->container, $definition); @@ -189,7 +189,7 @@ public function getStorageController($entity_type) { */ public function getListController($entity_type) { if (!isset($this->controllers['listing'][$entity_type])) { - $definition = $this->getDefinition($entity_type); + $definition = $this->getEntityTypeForReal($entity_type); $class = $definition->getList(); if (in_array('Drupal\Core\Entity\EntityControllerInterface', class_implements($class))) { $controller = $class::createInstance($this->container, $definition); @@ -208,7 +208,7 @@ public function getListController($entity_type) { */ public function getFormController($entity_type, $operation) { if (!isset($this->controllers['form'][$operation][$entity_type])) { - $class = $this->getDefinition($entity_type)->getForm($operation); + $class = $this->getEntityTypeForReal($entity_type)->getForm($operation); if (in_array('Drupal\Core\DependencyInjection\ContainerInjectionInterface', class_implements($class))) { $controller = $class::create($this->container); } @@ -230,7 +230,7 @@ public function getFormController($entity_type, $operation) { */ public function getViewBuilder($entity_type) { if (!isset($this->controllers['view_builder'][$entity_type])) { - $definition = $this->getDefinition($entity_type); + $definition = $this->getEntityTypeForReal($entity_type); $class = $definition->getViewBuilder(); if (in_array('Drupal\Core\Entity\EntityControllerInterface', class_implements($class))) { $controller = $class::createInstance($this->container, $definition); @@ -248,7 +248,7 @@ public function getViewBuilder($entity_type) { */ public function getAccessController($entity_type) { if (!isset($this->controllers['access'][$entity_type])) { - $definition = $this->getDefinition($entity_type); + $definition = $this->getEntityTypeForReal($entity_type); $class = $definition->getAccess(); if (in_array('Drupal\Core\Entity\EntityControllerInterface', class_implements($class))) { $controller = $class::createInstance($this->container, $definition); @@ -263,6 +263,25 @@ public function getAccessController($entity_type) { } /** + * Returns an entity type, or throws an exception if it doesn't exist. + * + * @param string $entity_type_id + * The entity type ID. + * + * @return \Drupal\Core\Entity\EntityTypeInterface + * The entity type object. + * + * @throws \InvalidArgumentException + */ + protected function getEntityTypeForReal($entity_type_id) { + if ($definition = $this->getDefinition($entity_type_id)) { + return $definition; + } + + throw new \InvalidArgumentException(sprintf('The %s entity type does not exist.', $entity_type_id)); + } + + /** * {@inheritdoc} */ public function getForm(EntityInterface $entity, $operation = 'default', array $form_state = array()) { @@ -476,22 +495,4 @@ public function getTranslationFromContext(EntityInterface $entity, $langcode = N return $translation; } - /** - * {@inheritdoc} - * - * @return \Drupal\Core\Entity\EntityTypeInterface - */ - public function getDefinition($plugin_id) { - return parent::getDefinition($plugin_id); - } - - /** - * {@inheritdoc} - * - * @return \Drupal\Core\Entity\EntityTypeInterface[] - */ - public function getDefinitions() { - return parent::getDefinitions(); - } - } diff --git a/core/modules/config_translation/lib/Drupal/config_translation/Controller/ConfigTranslationListController.php b/core/modules/config_translation/lib/Drupal/config_translation/Controller/ConfigTranslationListController.php index 14bd763..4920863 100644 --- a/core/modules/config_translation/lib/Drupal/config_translation/Controller/ConfigTranslationListController.php +++ b/core/modules/config_translation/lib/Drupal/config_translation/Controller/ConfigTranslationListController.php @@ -76,7 +76,8 @@ public function listing() { // list controller. $class = $this->mapperDefinition['list_controller']; /** @var \Drupal\config_translation\Controller\ConfigTranslationEntityListControllerInterface $controller */ - $controller = new $class($this->entityManager()->getDefinition($entity_type), $this->entityManager()->getStorageController($entity_type), $this->moduleHandler(), $this->entityManager(), $this->mapperDefinition); + $controller = new $class($this->entityManager()->getDefinition($entity_type), $this->entityManager()->getStorageController($entity_type), $this->entityManager(), $this->mapperDefinition); + $controller->setModuleHandler($this->moduleHandler()); $build = $controller->render(); $build['#title'] = $this->mapper->getTypeLabel(); return $build; diff --git a/core/modules/field/field.views.inc b/core/modules/field/field.views.inc index e9e65c4..172aee4 100644 --- a/core/modules/field/field.views.inc +++ b/core/modules/field/field.views.inc @@ -67,13 +67,8 @@ function field_views_data_alter(&$data) { */ function _field_views_is_sql_entity_type(FieldInterface $field) { $entity_manager = \Drupal::entityManager(); - try { - if ($entity_manager->getStorageController($field->entity_type) instanceof FieldableDatabaseStorageController) { - return TRUE; - } - } - catch (\InvalidArgumentException $e) { - // Disabled entity type, nothing to do. + if ($entity_manager->getDefinition($field->entity_type) && $entity_manager->getStorageController($field->entity_type) instanceof FieldableDatabaseStorageController) { + return TRUE; } } diff --git a/core/modules/simpletest/lib/Drupal/simpletest/Tests/DrupalUnitTestBaseTest.php b/core/modules/simpletest/lib/Drupal/simpletest/Tests/DrupalUnitTestBaseTest.php index 79b65b5..6c7d52c 100644 --- a/core/modules/simpletest/lib/Drupal/simpletest/Tests/DrupalUnitTestBaseTest.php +++ b/core/modules/simpletest/lib/Drupal/simpletest/Tests/DrupalUnitTestBaseTest.php @@ -199,7 +199,7 @@ function testInstallConfig() { */ function testEnableModulesFixedList() { // Install system module. - $this->container->get('module_handler')->install(array('system')); + $this->container->get('module_handler')->install(array('system', 'menu_link')); $entity_manager = \Drupal::entityManager(); // entity_test is loaded via $modules; its entity type should exist. diff --git a/core/modules/views/lib/Drupal/views/Tests/Plugin/DisplayPageTest.php b/core/modules/views/lib/Drupal/views/Tests/Plugin/DisplayPageTest.php index b0d830b..b260a74 100644 --- a/core/modules/views/lib/Drupal/views/Tests/Plugin/DisplayPageTest.php +++ b/core/modules/views/lib/Drupal/views/Tests/Plugin/DisplayPageTest.php @@ -33,7 +33,7 @@ class DisplayPageTest extends ViewUnitTestBase { * * @var array */ - public static $modules = array('system', 'user', 'menu_link', 'field'); + public static $modules = array('system', 'user', 'menu_link', 'field', 'entity'); /** * The router dumper to get all routes. diff --git a/core/modules/views_ui/tests/Drupal/views_ui/Tests/ViewListControllerTest.php b/core/modules/views_ui/tests/Drupal/views_ui/Tests/ViewListControllerTest.php index d058288..eaa5066 100644 --- a/core/modules/views_ui/tests/Drupal/views_ui/Tests/ViewListControllerTest.php +++ b/core/modules/views_ui/tests/Drupal/views_ui/Tests/ViewListControllerTest.php @@ -120,12 +120,10 @@ public function testBuildRowEntityList() { $container->set('string_translation', $this->getStringTranslationStub()); \Drupal::setContainer($container); - $module_handler = $this->getMock('Drupal\Core\Extension\ModuleHandlerInterface'); - // Setup a view list controller with a mocked buildOperations method, // because t() is called on there. $entity_type = $this->getMock('Drupal\Core\Entity\EntityTypeInterface'); - $view_list_controller = $this->getMock('Drupal\views_ui\ViewListController', array('buildOperations'), array($storage_controller, $entity_type, $display_manager, $module_handler)); + $view_list_controller = $this->getMock('Drupal\views_ui\ViewListController', array('buildOperations'), array($entity_type, $storage_controller, $display_manager)); $view_list_controller->expects($this->any()) ->method('buildOperations') ->will($this->returnValue(array()));