You are here

class SetInlineBlockDependencyWithContextTranslation in Layout Builder Asymmetric Translation 8.2

Takes over \Drupal\layout_builder\EventSubscriber\SetInlineBlockDependency to load the entity with the correct translation.

Hierarchy

Expanded class hierarchy of SetInlineBlockDependencyWithContextTranslation

File

src/EventSubscriber/SetInlineBlockDependencyWithContextTranslation.php, line 12

Namespace

Drupal\layout_builder_at\EventSubscriber
View source
class SetInlineBlockDependencyWithContextTranslation extends SetInlineBlockDependency {

  /**
   * Call getTranslationFromContext() on the entity.
   */
  protected function getInlineBlockDependency(BlockContentInterface $block_content) {
    $layout_entity_info = $this->usage
      ->getUsage($block_content
      ->id());
    if (empty($layout_entity_info)) {

      // If the block does not have usage information then we cannot set a
      // dependency. It may be used by another module besides layout builder.
      return NULL;
    }
    $layout_entity_storage = $this->entityTypeManager
      ->getStorage($layout_entity_info->layout_entity_type);
    $layout_entity = $layout_entity_storage
      ->load($layout_entity_info->layout_entity_id);
    $layout_entity = \Drupal::service('entity.repository')
      ->getTranslationFromContext($layout_entity);
    if ($this
      ->isLayoutCompatibleEntity($layout_entity)) {
      if ($this
        ->isBlockRevisionUsedInEntity($layout_entity, $block_content)) {
        return $layout_entity;
      }
    }
    return NULL;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
LayoutEntityHelperTrait::$sectionStorageManager protected property The section storage manager. 1
LayoutEntityHelperTrait::getEntitySections protected function Gets the sections for an entity if any.
LayoutEntityHelperTrait::getInlineBlockComponents protected function Gets components that have Inline Block plugins.
LayoutEntityHelperTrait::getInlineBlockRevisionIdsInSections protected function Gets revision IDs for layout sections.
LayoutEntityHelperTrait::getSectionStorageForEntity protected function Gets the section storage for an entity.
LayoutEntityHelperTrait::isEntityUsingFieldOverride Deprecated protected function Determines if an entity is using a field for the layout override.
LayoutEntityHelperTrait::isLayoutCompatibleEntity protected function Determines if an entity can have a layout.
LayoutEntityHelperTrait::originalEntityUsesDefaultStorage protected function Determines if the original entity used the default section storage.
LayoutEntityHelperTrait::sectionStorageManager private function Gets the section storage manager. 1
SetInlineBlockDependency::$database protected property The database connection.
SetInlineBlockDependency::$entityTypeManager protected property The entity type manager.
SetInlineBlockDependency::$usage protected property The inline block usage service.
SetInlineBlockDependency::getSubscribedEvents public static function Returns an array of event names this subscriber wants to listen to.
SetInlineBlockDependency::isBlockRevisionUsedInEntity protected function Determines if a block content revision is used in an entity.
SetInlineBlockDependency::onGetDependency public function Handles the BlockContentEvents::INLINE_BLOCK_GET_DEPENDENCY event.
SetInlineBlockDependency::__construct public function Constructs SetInlineBlockDependency object.
SetInlineBlockDependencyWithContextTranslation::getInlineBlockDependency protected function Call getTranslationFromContext() on the entity. Overrides SetInlineBlockDependency::getInlineBlockDependency