diff --git a/core/includes/entity.inc b/core/includes/entity.inc index 221f2de..70d187d 100644 --- a/core/includes/entity.inc +++ b/core/includes/entity.inc @@ -46,6 +46,18 @@ function entity_info_cache_clear() { } /** + * Clears the entity render cache for all entity types. + */ +function entity_render_cache_clear() { + $entity_manager = drupal_container()->get('plugin.manager.entity'); + foreach ($entity_manager->getDefinitions() as $entity_type => $info) { + if (isset($info['render_controller_class'])) { + $entity_manager->getRenderController($entity_type)->resetCache(); + } + } +} + +/** * Returns the entity bundle info. * * @param string|null $entity_type diff --git a/core/lib/Drupal/Core/Entity/EntityRenderController.php b/core/lib/Drupal/Core/Entity/EntityRenderController.php index 321e21a..d1f2bfa 100644 --- a/core/lib/Drupal/Core/Entity/EntityRenderController.php +++ b/core/lib/Drupal/Core/Entity/EntityRenderController.php @@ -205,10 +205,10 @@ public function resetCache(array $entities = NULL) { if (isset($entities)) { $tags = array(); foreach ($entities as $entity) { - $tags[$this->entityType][] = $entity->id(); + $tags[$this->entityType][$entity->id()] = $entity->id(); // @todo Remove when all entities are converted to EntityNG. - if (!$entity->getPropertyDefinitions()) { + if ($entity->getPropertyDefinitions() === NULL) { continue; } @@ -216,8 +216,8 @@ public function resetCache(array $entities = NULL) { // cleared. foreach ($entity->getPropertyDefinitions() as $name => $definition) { if ($definition['type'] == 'entity_reference_field') { - foreach ($entity->$name->getValue() as $target_id) { - $tags[$definition['settings']['target_type']][$target_id] = $target_id; + foreach ($entity->$name->getValue() as $value) { + $tags[$definition['settings']['target_type']][$value['target_id']] = $value['target_id']; } } } diff --git a/core/modules/user/lib/Drupal/user/Tests/UserSignatureTest.php b/core/modules/user/lib/Drupal/user/Tests/UserSignatureTest.php index b539201..ab4c706 100644 --- a/core/modules/user/lib/Drupal/user/Tests/UserSignatureTest.php +++ b/core/modules/user/lib/Drupal/user/Tests/UserSignatureTest.php @@ -118,9 +118,6 @@ function testUserSignature() { $edit['comment_body[' . $langcode . '][0][format]'] = $this->full_html_format->format; $this->drupalPost('comment/' . $comment_id . '/edit', $edit, t('Save')); - // @todo Temporary cache clear. - drupal_container()->get('plugin.manager.entity')->getRenderController('node')->resetCache(array($node)); - // Assert that the signature did not make it through unfiltered. $this->drupalGet('node/' . $node->nid); $this->assertNoRaw($signature_text, 'Unfiltered signature text not found.'); diff --git a/core/modules/user/user.module b/core/modules/user/user.module index fa6a291..0ae5458 100644 --- a/core/modules/user/user.module +++ b/core/modules/user/user.module @@ -1982,6 +1982,8 @@ function user_role_grant_permissions($rid, array $permissions = array()) { // Clear the user access cache. drupal_static_reset('user_access'); drupal_static_reset('user_role_permissions'); + // Entity render cache is based on user roles, so we need to clear it as well. + entity_render_cache_clear(); } /** @@ -2005,6 +2007,8 @@ function user_role_revoke_permissions($rid, array $permissions = array()) { // Clear the user access cache. drupal_static_reset('user_access'); drupal_static_reset('user_role_permissions'); + // Entity render cache is based on user roles, so we need to clear it as well. + entity_render_cache_clear(); } /**