diff --git a/core/includes/entity.inc b/core/includes/entity.inc index 2565630..2db6453 100644 --- a/core/includes/entity.inc +++ b/core/includes/entity.inc @@ -644,7 +644,7 @@ function entity_render_controller($entity_type) { function entity_view(EntityInterface $entity, $view_mode, $langcode = NULL, $reset = FALSE) { $render_controller = Drupal::entityManager()->getRenderController($entity->entityType()); if ($reset) { - $render_controller->resetCache(array($entity)); + $render_controller->resetCache(array($entity->id())); } return $render_controller->view($entity, $view_mode, $langcode); } @@ -670,7 +670,7 @@ function entity_view(EntityInterface $entity, $view_mode, $langcode = NULL, $res function entity_view_multiple(array $entities, $view_mode, $langcode = NULL, $reset = FALSE) { $render_controller = Drupal::entityManager()->getRenderController(reset($entities)->entityType()); if ($reset) { - $render_controller->resetCache($entities); + $render_controller->resetCache(array_keys($entities)); } return $render_controller->viewMultiple($entities, $view_mode, $langcode); } diff --git a/core/lib/Drupal/Core/Entity/Entity.php b/core/lib/Drupal/Core/Entity/Entity.php index 36e5287..908b36c 100644 --- a/core/lib/Drupal/Core/Entity/Entity.php +++ b/core/lib/Drupal/Core/Entity/Entity.php @@ -14,7 +14,6 @@ use Drupal\Core\TypedData\TypedDataInterface; use IteratorAggregate; use Drupal\Core\Session\AccountInterface; -use Drupal\Core\Cache\Cache; /** * Defines a base entity class. @@ -652,18 +651,16 @@ public function initTranslation($langcode) { */ public function relatedEntities() { $relationships = array(); - $id = $this->id(); // @todo Remove when all entities are converted to EntityNG. if (!$this->getPropertyDefinitions()) { return $relationships; } - // Add all the referenced entity types and IDs to the tags that will be - // cleared. + // Gather a list of related entities. foreach ($this->getProperties() as $name => $definition) { - $property = $this->get($name)->offsetGet(0); - if ($property instanceof EntityReferenceItem && $entity = $property->entity) { + $field_item = $this->get($name)->offsetGet(0); + if ($field_item instanceof EntityReferenceItem && $entity = $field_item->entity) { $relationships[] = $entity; } } @@ -675,23 +672,19 @@ public function relatedEntities() { * {@inheritdoc} */ public function changed() { - $tags = array( - $this->entityType() => array($this->id()), + $related_entity_ids = array( + $this->entityType() => array($this->id() => TRUE), ); foreach ($this->relatedEntities() as $related_entity) { - $related_entity_type = $related_entity->entityType(); + $related_entity_ids[$related_entity->entityType()][$related_entity->id()] = TRUE; + } - if (!isset($tags[$related_entity_type])) { - $tags[$related_entity_type] = array(); + foreach ($related_entity_ids as $entity_type => $entity_ids) { + if (\Drupal::entityManager()->hasController($entity_type, 'render')) { + \Drupal::entityManager()->getRenderController($entity_type)->resetCache(array_keys($entity_ids)); } - - $tags[$related_entity_type][] = $related_entity->id(); } - - // @todo: Move cache tag invalidation to an event listener so that the - // service isn't required here. - Cache::deleteTags($tags); } } diff --git a/core/lib/Drupal/Core/Entity/EntityManager.php b/core/lib/Drupal/Core/Entity/EntityManager.php index 4766a91..b5d4ed6 100644 --- a/core/lib/Drupal/Core/Entity/EntityManager.php +++ b/core/lib/Drupal/Core/Entity/EntityManager.php @@ -155,6 +155,7 @@ public function getControllerClass($entity_type, $controller_type, $nested = NUL $definition = $this->getDefinition($entity_type); $definition = $definition['controllers']; if (empty($definition[$controller_type])) { + debug(format_backtrace(debug_backtrace(TRUE))); throw new \InvalidArgumentException(sprintf('The entity (%s) did not specify a %s.', $entity_type, $controller_type)); } diff --git a/core/lib/Drupal/Core/Entity/EntityRenderController.php b/core/lib/Drupal/Core/Entity/EntityRenderController.php index 54f8ca1..40af2eb 100644 --- a/core/lib/Drupal/Core/Entity/EntityRenderController.php +++ b/core/lib/Drupal/Core/Entity/EntityRenderController.php @@ -214,31 +214,11 @@ public function viewMultiple(array $entities = array(), $view_mode = 'full', $la /** * {@inheritdoc} */ - public function resetCache(array $entities = NULL) { - if (isset($entities)) { + public function resetCache(array $ids = NULL) { + if (isset($ids)) { $tags = array(); - foreach ($entities as $entity) { - $id = $entity->id(); - $tags[$this->entityType][$id] = $id; - - // @todo Remove when all entities are converted to EntityNG. - if (!$entity->getPropertyDefinitions()) { - continue; - } - - // Add all the referenced entity types and IDs to the tags that will be - // cleared. - foreach ($entity->getProperties() as $name => $definition) { - if ($entity->get($name)->offsetGet(0) instanceof EntityReferenceItem && $field_values = $entity->get($name)->getValue()) { - foreach (array_filter($field_values) as $value) { - // @todo This looks very ugly, ask the Entity API people for a - // nicer way to do it. - $field_item_definition = $entity->get($name)->offsetGet(0)->getPropertyDefinitions(); - $target_entity_type = $field_item_definition['entity']['constraints']['EntityType']; - $tags[$target_entity_type][$value['target_id']] = $value['target_id']; - } - } - } + foreach ($ids as $entity_id) { + $tags[$this->entityType][$entity_id] = $entity_id; } \Drupal::cache($this->cacheBin)->deleteTags($tags); } diff --git a/core/lib/Drupal/Core/Entity/EntityRenderControllerInterface.php b/core/lib/Drupal/Core/Entity/EntityRenderControllerInterface.php index eb8f41b..a112fc2 100644 --- a/core/lib/Drupal/Core/Entity/EntityRenderControllerInterface.php +++ b/core/lib/Drupal/Core/Entity/EntityRenderControllerInterface.php @@ -79,9 +79,10 @@ public function viewMultiple(array $entities = array(), $view_mode = 'full', $la /** * Resets the entity render cache. * - * @param array|null $entities - * (optional) If specified, the cache is reset for the given entities only. + * @param array|null $ids + * (optional) If specified, the cache is reset for the given entity IDs + * only. */ - public function resetCache(array $entities = NULL); + public function resetCache(array $ids = NULL); } diff --git a/core/modules/block/lib/Drupal/block/BlockRenderController.php b/core/modules/block/lib/Drupal/block/BlockRenderController.php index 5523696..0f52818 100644 --- a/core/modules/block/lib/Drupal/block/BlockRenderController.php +++ b/core/modules/block/lib/Drupal/block/BlockRenderController.php @@ -65,7 +65,7 @@ public function viewMultiple(array $entities = array(), $view_mode = 'full', $la /** * {@inheritdoc} */ - public function resetCache(array $entities = NULL) { + public function resetCache(array $ids = NULL) { // @todo Move block render caching logic to this controller? } } diff --git a/core/modules/entity/lib/Drupal/entity/EntityDisplayModeBase.php b/core/modules/entity/lib/Drupal/entity/EntityDisplayModeBase.php index eb36cd2..1541143 100644 --- a/core/modules/entity/lib/Drupal/entity/EntityDisplayModeBase.php +++ b/core/modules/entity/lib/Drupal/entity/EntityDisplayModeBase.php @@ -58,6 +58,13 @@ public $status = TRUE; /** + * Whether or not the rendered output of this view mode is cached by default. + * + * @var bool + */ + public $cache = TRUE; + + /** * {@inheritdoc} */ public static function sort($a, $b) { @@ -75,11 +82,4 @@ public function getTargetType() { return $this->targetEntityType; } - /** - * Whether or not the rendered output of this view mode is cached by default. - * - * @var bool - */ - public $cache = TRUE; - } diff --git a/core/modules/file/config/entity.view_mode.file.full.yml b/core/modules/file/config/entity.view_mode.file.full.yml deleted file mode 100644 index 4d4ed1f..0000000 --- a/core/modules/file/config/entity.view_mode.file.full.yml +++ /dev/null @@ -1,5 +0,0 @@ -id: file.full -label: File default -status: '0' -cache: '1' -targetEntityType: file diff --git a/core/modules/node/node.module b/core/modules/node/node.module index 8aba3ea..92512f4 100644 --- a/core/modules/node/node.module +++ b/core/modules/node/node.module @@ -1750,7 +1750,7 @@ function _node_index_node(EntityInterface $node) { foreach ($languages as $language) { // Render the node. - $build = entity_view($node, 'search_index', $language->langcode, TRUE); + $build = node_view($node, 'search_index', $language->id); unset($build['#theme']); $node->rendered = drupal_render($build); diff --git a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityUnitTestBase.php b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityUnitTestBase.php index 34fb4cc..b1746ae 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityUnitTestBase.php +++ b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityUnitTestBase.php @@ -42,7 +42,7 @@ public function setUp() { $this->entityManager = $this->container->get('plugin.manager.entity'); $this->state = $this->container->get('state'); - $this->installSchema('user', 'users'); + $this->installSchema('user', array('users', 'users_roles')); $this->installSchema('system', 'sequences'); $this->installSchema('entity_test', 'entity_test'); $this->installConfig(array('field')); diff --git a/core/modules/system/lib/Drupal/system/Tests/System/DateTimeTest.php b/core/modules/system/lib/Drupal/system/Tests/System/DateTimeTest.php index ab4cb04..31ffbdf 100644 --- a/core/modules/system/lib/Drupal/system/Tests/System/DateTimeTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/System/DateTimeTest.php @@ -65,7 +65,7 @@ function testTimeZoneHandling() { // Set time zone to Los Angeles time. $config->set('default', 'America/Los_Angeles')->save(); - \Drupal::entityManager()->getRenderController('node')->resetCache(array($node1, $node2)); + \Drupal::entityManager()->getRenderController('node')->resetCache(array($node1->id(), $node2->id())); // Confirm date format and time zone. $this->drupalGet("node/$node1->nid"); diff --git a/core/modules/system/tests/modules/entity_test/entity_test.module b/core/modules/system/tests/modules/entity_test/entity_test.module index 05498f7..cd1086a 100644 --- a/core/modules/system/tests/modules/entity_test/entity_test.module +++ b/core/modules/system/tests/modules/entity_test/entity_test.module @@ -143,15 +143,17 @@ function entity_test_entity_bundle_info() { function entity_test_entity_view_mode_info_alter(&$view_modes) { $entity_info = entity_get_info(); foreach ($entity_info as $entity_type => $info) { - if ($entity_info[$entity_type]['module'] == 'entity_test') { + if ($entity_info[$entity_type]['module'] == 'entity_test' && !isset($view_modes[$entity_type])) { $view_modes[$entity_type] = array( 'full' => array( 'label' => t('Full object'), 'status' => TRUE, + 'cache' => TRUE, ), 'teaser' => array( 'label' => t('Teaser'), 'status' => TRUE, + 'cache' => TRUE, ), ); } diff --git a/core/modules/taxonomy/config/entity.view_mode.taxonomy_vocabulary.full.yml b/core/modules/taxonomy/config/entity.view_mode.taxonomy_vocabulary.full.yml deleted file mode 100644 index 8961a6f..0000000 --- a/core/modules/taxonomy/config/entity.view_mode.taxonomy_vocabulary.full.yml +++ /dev/null @@ -1,5 +0,0 @@ -id: vocabulary.full -label: Taxonomy vocabulary -status: '0' -cache: '1' -targetEntityType: taxonomy_vocabulary diff --git a/core/modules/user/lib/Drupal/user/Tests/UserPictureTest.php b/core/modules/user/lib/Drupal/user/Tests/UserPictureTest.php index 280b645..551cc68 100644 --- a/core/modules/user/lib/Drupal/user/Tests/UserPictureTest.php +++ b/core/modules/user/lib/Drupal/user/Tests/UserPictureTest.php @@ -121,8 +121,8 @@ function testPictureOnNodeComment() { ->set('features.node_user_picture', FALSE) ->set('features.comment_user_picture', FALSE) ->save(); - \Drupal::entityManager()->getStorageController('node')->resetCache(array($node)); - \Drupal::entityManager()->getStorageController('comment')->resetCache(); + \Drupal::entityManager()->getRenderController('node')->resetCache(array($node->id())); + \Drupal::entityManager()->getRenderController('comment')->resetCache(); $this->drupalGet('node/' . $node->nid); $this->assertNoRaw(file_uri_target($file->getFileUri()), 'User picture not found on node and comment.');