core/lib/Drupal/Core/Entity/Entity.php | 26 ++++++++++++-------- .../comment/Tests/Entity/CommentLockTest.php | 1 + 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/core/lib/Drupal/Core/Entity/Entity.php b/core/lib/Drupal/Core/Entity/Entity.php index b7c23c4..27f9895 100644 --- a/core/lib/Drupal/Core/Entity/Entity.php +++ b/core/lib/Drupal/Core/Entity/Entity.php @@ -320,17 +320,8 @@ public function preSave(EntityStorageControllerInterface $storage_controller) { */ public function postSave(EntityStorageControllerInterface $storage_controller, $update = TRUE) { $this->onSaveOrDelete(); - - // If this entity is a bundle entity type of another entity type, and we've - // updating an existing entity, and that other entity type has a view - // builder class, then invalidate the render cache of entities for which - // this entity is a bundle. if ($update) { - $bundle_of = $this->getEntityType()->getBundleOf(); - $entity_manager = \Drupal::entityManager(); - if ($bundle_of !== FALSE && $entity_manager->hasController($bundle_of, 'view_builder')) { - $entity_manager->getViewBuilder($bundle_of)->resetCache(); - } + $this->onUpdateBundleEntity(); } } @@ -394,6 +385,21 @@ protected function onSaveOrDelete() { } /** + * Acts on entities of which this entity is a bundle entity type. + */ + protected function onUpdateBundleEntity() { + // If this entity is a bundle entity type of another entity type, and we're + // updating an existing entity, and that other entity type has a view + // builder class, then invalidate the render cache of entities for which + // this entity is a bundle. + $bundle_of = $this->getEntityType()->getBundleOf(); + $entity_manager = \Drupal::entityManager(); + if ($bundle_of !== FALSE && $entity_manager->hasController($bundle_of, 'view_builder')) { + $entity_manager->getViewBuilder($bundle_of)->resetCache(); + } + } + + /** * Wraps the URL generator. * * @return \Drupal\Core\Routing\UrlGeneratorInterface diff --git a/core/modules/comment/tests/Drupal/comment/Tests/Entity/CommentLockTest.php b/core/modules/comment/tests/Drupal/comment/Tests/Entity/CommentLockTest.php index a0afe1a..1d54be4 100644 --- a/core/modules/comment/tests/Drupal/comment/Tests/Entity/CommentLockTest.php +++ b/core/modules/comment/tests/Drupal/comment/Tests/Entity/CommentLockTest.php @@ -54,6 +54,7 @@ public function testLocks() { unset($methods[array_search('preSave', $methods)]); unset($methods[array_search('postSave', $methods)]); $methods[] = 'onSaveOrDelete'; + $methods[] = 'onUpdateBundleEntity'; $comment = $this->getMockBuilder('Drupal\comment\Entity\Comment') ->disableOriginalConstructor() ->setMethods($methods)