diff --git a/core/modules/block_content/src/BlockContentViewBuilder.php b/core/modules/block_content/src/BlockContentViewBuilder.php index 322a087..f8e2113 100644 --- a/core/modules/block_content/src/BlockContentViewBuilder.php +++ b/core/modules/block_content/src/BlockContentViewBuilder.php @@ -33,17 +33,6 @@ public function viewMultiple(array $entities = array(), $view_mode = 'full', $la /** * {@inheritdoc} */ - protected function getBuildDefaults(EntityInterface $entity, $view_mode) { - $build = parent::getBuildDefaults($entity, $view_mode); - // The custom block will be rendered in the wrapped block template already - // and thus has no entity template itself. - unset($build['#theme']); - return $build; - } - - /** - * {@inheritdoc} - */ protected function alterBuild(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display, $view_mode) { parent::alterBuild($build, $entity, $display, $view_mode); // Add contextual links for this custom block. diff --git a/core/modules/contact/src/MessageViewBuilder.php b/core/modules/contact/src/MessageViewBuilder.php index 3024f62..6b88a8e 100644 --- a/core/modules/contact/src/MessageViewBuilder.php +++ b/core/modules/contact/src/MessageViewBuilder.php @@ -15,17 +15,6 @@ class MessageViewBuilder extends EntityViewBuilder { /** * {@inheritdoc} */ - protected function getBuildDefaults(EntityInterface $entity, $view_mode) { - $build = parent::getBuildDefaults($entity, $view_mode); - // The message fields are individually rendered into email templates, so - // the entity has no template itself. - unset($build['#theme']); - return $build; - } - - /** - * {@inheritdoc} - */ public function buildComponents(array &$build, array $entities, array $displays, $view_mode) { parent::buildComponents($build, $entities, $displays, $view_mode); diff --git a/core/modules/shortcut/tests/src/Kernel/ShortcutEntityTest.php b/core/modules/shortcut/tests/src/Kernel/ShortcutEntityTest.php deleted file mode 100644 index c247667..0000000 --- a/core/modules/shortcut/tests/src/Kernel/ShortcutEntityTest.php +++ /dev/null @@ -1,38 +0,0 @@ -installConfig(['shortcut']); - - $entity_type_manager = \Drupal::entityTypeManager(); - $entity_type = $entity_type_manager->getDefinition('shortcut'); - $this->assertTrue($entity_type->hasViewBuilderClass()); - - $shortcut = Shortcut::create(['shortcut_set' => 'default']); - - $build = $entity_type_manager->getViewBuilder('shortcut')->view($shortcut); - $this->assertEquals($shortcut, $build['#shortcut']); - $this->assertFalse(array_key_exists('#theme', $build)); - } - -} diff --git a/core/modules/system/tests/modules/entity_test/src/EntityTestViewBuilder.php b/core/modules/system/tests/modules/entity_test/src/EntityTestViewBuilder.php index 90eaf30..061dfaf 100644 --- a/core/modules/system/tests/modules/entity_test/src/EntityTestViewBuilder.php +++ b/core/modules/system/tests/modules/entity_test/src/EntityTestViewBuilder.php @@ -15,15 +15,6 @@ class EntityTestViewBuilder extends EntityViewBuilder { /** * {@inheritdoc} */ - protected function getBuildDefaults(EntityInterface $entity, $view_mode) { - $build = parent::getBuildDefaults($entity, $view_mode); - unset($build['#theme']); - return $build; - } - - /** - * {@inheritdoc} - */ public function buildComponents(array &$build, array $entities, array $displays, $view_mode) { parent::buildComponents($build, $entities, $displays, $view_mode); diff --git a/core/tests/Drupal/KernelTests/Core/Entity/EntityViewBuilderTest.php b/core/tests/Drupal/KernelTests/Core/Entity/EntityViewBuilderTest.php index 156b799..f838004 100644 --- a/core/tests/Drupal/KernelTests/Core/Entity/EntityViewBuilderTest.php +++ b/core/tests/Drupal/KernelTests/Core/Entity/EntityViewBuilderTest.php @@ -2,6 +2,7 @@ namespace Drupal\KernelTests\Core\Entity; +use Drupal\Core\Entity\ContentEntityTypeInterface; use Drupal\Core\Language\LanguageInterface; use Drupal\field\Tests\EntityReference\EntityReferenceTestTrait; use Drupal\Core\Cache\Cache; @@ -210,4 +211,66 @@ protected function createTestEntity($entity_type) { return $this->container->get('entity.manager')->getStorage($entity_type)->create($data); } + /** + * Tests that viewing a shortcut does not use a shortcut template. + */ + public function testEntityViewBuilderDefaultBuild() { + // Enable all the content entity provider modules in core. + $modules = [ + 'aggregator', + 'block_content', + 'comment', + 'contact', + 'content_moderation', + 'file', + 'menu_link_content', + 'node', + 'shortcut', + 'taxonomy', + // Required for aggregator. + 'options', + // Required for menu_link_content. + 'link', + ]; + foreach ($modules as $module) { + $this->installModule($module); + } + // All core content entities. + $entity_types = [ + 'aggregator_feed', + 'aggregator_item', + 'block_content', + 'comment', + 'contact_message', + 'content_moderation_state', + 'file', + 'menu_link_content', + 'node', + 'shortcut', + 'taxonomy_term', + ]; + foreach ($entity_types as $entity_type) { + $this->installEntitySchema($entity_type); + } + + $entity_type_manager = \Drupal::entityTypeManager(); + foreach ($entity_type_manager->getDefinitions() as $entity_type_id => $entity_type) { + if ($entity_type instanceof ContentEntityTypeInterface && $entity_type->getProvider() != 'entity_test') { + $this->assertTrue($entity_type->hasViewBuilderClass(), $entity_type->getLabel()); + $entity = $entity_type_manager + ->getStorage($entity_type_id) + ->create(); + $build = $entity_type_manager + ->getViewBuilder($entity_type_id) + ->view($entity); + if (\Drupal::service('theme.registry')->getRuntime()->has($entity_type_id)) { + $this->assertTrue(array_key_exists('#theme', $build)); + } + else { + $this->assertFalse(array_key_exists('#theme', $build)); + } + } + } + } + }