Chris@17: isEntityUsingFieldOverride($entity); Chris@17: } Chris@17: Chris@17: /** Chris@17: * Gets revision IDs for layout sections. Chris@17: * Chris@17: * @param \Drupal\layout_builder\Section[] $sections Chris@17: * The layout sections. Chris@17: * Chris@17: * @return int[] Chris@17: * The revision IDs. Chris@17: */ Chris@17: protected function getInlineBlockRevisionIdsInSections(array $sections) { Chris@17: $revision_ids = []; Chris@17: foreach ($this->getInlineBlockComponents($sections) as $component) { Chris@17: $configuration = $component->getPlugin()->getConfiguration(); Chris@17: if (!empty($configuration['block_revision_id'])) { Chris@17: $revision_ids[] = $configuration['block_revision_id']; Chris@17: } Chris@17: } Chris@17: return $revision_ids; Chris@17: } Chris@17: Chris@17: /** Chris@17: * Gets the sections for an entity if any. Chris@17: * Chris@17: * @todo Replace this method with calls to the SectionStorageManagerInterface Chris@17: * method for getting sections from an entity in Chris@17: * https://www.drupal.org/node/2986403. Chris@17: * Chris@17: * @param \Drupal\Core\Entity\EntityInterface $entity Chris@17: * The entity. Chris@17: * Chris@17: * @return \Drupal\layout_builder\Section[]|null Chris@17: * The entity layout sections if available. Chris@17: */ Chris@17: protected function getEntitySections(EntityInterface $entity) { Chris@17: if ($entity instanceof LayoutEntityDisplayInterface) { Chris@17: return $entity->getSections(); Chris@17: } Chris@17: elseif ($this->isEntityUsingFieldOverride($entity)) { Chris@17: return $entity->get(OverridesSectionStorage::FIELD_NAME)->getSections(); Chris@17: } Chris@17: return NULL; Chris@17: } Chris@17: Chris@17: /** Chris@17: * Gets components that have Inline Block plugins. Chris@17: * Chris@17: * @param \Drupal\layout_builder\Section[] $sections Chris@17: * The layout sections. Chris@17: * Chris@17: * @return \Drupal\layout_builder\SectionComponent[] Chris@17: * The components that contain Inline Block plugins. Chris@17: */ Chris@17: protected function getInlineBlockComponents(array $sections) { Chris@17: $inline_block_components = []; Chris@17: foreach ($sections as $section) { Chris@17: foreach ($section->getComponents() as $component) { Chris@17: $plugin = $component->getPlugin(); Chris@17: if ($plugin instanceof DerivativeInspectionInterface && $plugin->getBaseId() === 'inline_block') { Chris@17: $inline_block_components[] = $component; Chris@17: } Chris@17: } Chris@17: } Chris@17: return $inline_block_components; Chris@17: } Chris@17: Chris@17: /** Chris@17: * Determines if an entity is using a field for the layout override. Chris@17: * Chris@17: * @param \Drupal\Core\Entity\EntityInterface $entity Chris@17: * The entity. Chris@17: * Chris@17: * @return bool Chris@17: * TRUE if the entity is using a field for a layout override. Chris@17: */ Chris@17: protected function isEntityUsingFieldOverride(EntityInterface $entity) { Chris@17: return $entity instanceof FieldableEntityInterface && $entity->hasField(OverridesSectionStorage::FIELD_NAME); Chris@17: } Chris@17: Chris@17: }