Mercurial > hg > isophonics-drupal-site
diff core/modules/layout_builder/src/InlineBlockEntityOperations.php @ 18:af1871eacc83
Update to Drupal core 8.7.1
author | Chris Cannam |
---|---|
date | Thu, 09 May 2019 15:33:08 +0100 |
parents | 129ea1e6d783 |
children |
line wrap: on
line diff
--- a/core/modules/layout_builder/src/InlineBlockEntityOperations.php Thu Feb 28 13:21:36 2019 +0000 +++ b/core/modules/layout_builder/src/InlineBlockEntityOperations.php Thu May 09 15:33:08 2019 +0100 @@ -8,12 +8,14 @@ use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Entity\RevisionableInterface; use Drupal\layout_builder\Plugin\Block\InlineBlock; +use Drupal\layout_builder\SectionStorage\SectionStorageManagerInterface; use Symfony\Component\DependencyInjection\ContainerInterface; /** * Defines a class for reacting to entity events related to Inline Blocks. * * @internal + * This is an internal utility class wrapping hook implementations. */ class InlineBlockEntityOperations implements ContainerInjectionInterface { @@ -22,7 +24,7 @@ /** * Inline block usage tracking service. * - * @var \Drupal\layout_builder\InlineBlockUsage + * @var \Drupal\layout_builder\InlineBlockUsageInterface */ protected $usage; @@ -43,17 +45,36 @@ /** * Constructs a new EntityOperations object. * + * @todo This constructor has one optional parameter, $section_storage_manager + * and one totally unused $database parameter. Deprecate the current + * constructor signature in https://www.drupal.org/node/3031492 after the + * general policy for constructor backwards compatibility is determined in + * https://www.drupal.org/node/3030640. + * * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager * The entity type manager service. - * @param \Drupal\layout_builder\InlineBlockUsage $usage + * @param \Drupal\layout_builder\InlineBlockUsageInterface $usage * Inline block usage tracking service. * @param \Drupal\Core\Database\Connection $database * The database connection. + * @param \Drupal\layout_builder\SectionStorage\SectionStorageManagerInterface $section_storage_manager + * (optional) The section storage manager. + * + * @todo The current constructor signature is deprecated: + * - The $section_storage_manager parameter is optional, but should become + * required. + * - The $database parameter is unused and should be removed. + * Deprecate in https://www.drupal.org/node/3031492. */ - public function __construct(EntityTypeManagerInterface $entityTypeManager, InlineBlockUsage $usage, Connection $database) { + public function __construct(EntityTypeManagerInterface $entityTypeManager, InlineBlockUsageInterface $usage, Connection $database, SectionStorageManagerInterface $section_storage_manager = NULL) { $this->entityTypeManager = $entityTypeManager; $this->blockContentStorage = $entityTypeManager->getStorage('block_content'); $this->usage = $usage; + if ($section_storage_manager === NULL) { + @trigger_error('The plugin.manager.layout_builder.section_storage service must be passed to \Drupal\layout_builder\InlineBlockEntityOperations::__construct(). It was added in Drupal 8.7.0 and will be required before Drupal 9.0.0.', E_USER_DEPRECATED); + $section_storage_manager = \Drupal::service('plugin.manager.layout_builder.section_storage'); + } + $this->sectionStorageManager = $section_storage_manager; } /** @@ -63,7 +84,8 @@ return new static( $container->get('entity_type.manager'), $container->get('inline_block.usage'), - $container->get('database') + $container->get('database'), + $container->get('plugin.manager.layout_builder.section_storage') ); } @@ -85,10 +107,10 @@ if ($entity->isNew() || !isset($entity->original) || $entity instanceof RevisionableInterface) { return; } - $sections = $this->getEntitySections($entity); - // If this is a layout override and there are no sections then it is a new - // override. - if ($this->isEntityUsingFieldOverride($entity) && empty($sections)) { + // If the original entity used the default storage then we cannot remove + // unused inline blocks because they will still be referenced in the + // defaults. + if ($this->originalEntityUsesDefaultStorage($entity)) { return; } @@ -132,9 +154,9 @@ * The parent entity. */ public function handleEntityDelete(EntityInterface $entity) { - if ($this->isLayoutCompatibleEntity($entity)) { - $this->usage->removeByLayoutEntity($entity); - } + // @todo In https://www.drupal.org/node/3008943 call + // \Drupal\layout_builder\LayoutEntityHelperTrait::isLayoutCompatibleEntity(). + $this->usage->removeByLayoutEntity($entity); } /** @@ -150,14 +172,10 @@ $duplicate_blocks = FALSE; if ($sections = $this->getEntitySections($entity)) { - if ($this->isEntityUsingFieldOverride($entity)) { - if (!$entity->isNew() && isset($entity->original)) { - if (empty($this->getEntitySections($entity->original))) { - // If there were no sections in the original entity then this is a - // new override from a default and the blocks need to be duplicated. - $duplicate_blocks = TRUE; - } - } + if ($this->originalEntityUsesDefaultStorage($entity)) { + // This is a new override from a default and the blocks need to be + // duplicated. + $duplicate_blocks = TRUE; } $new_revision = FALSE; if ($entity instanceof RevisionableInterface) {