You are here

final class InlineBlockEntityOperations in Layout Builder Symmetric Translations 8

Overrides cores InlineBlockEntityOperations to provide translation operations.

Hierarchy

Expanded class hierarchy of InlineBlockEntityOperations

1 file declares its use of InlineBlockEntityOperations
ClassResolver.php in src/DependencyInjection/ClassResolver.php

File

src/InlineBlockEntityOperations.php, line 12

Namespace

Drupal\layout_builder_st
View source
final class InlineBlockEntityOperations extends CoreInlineBlockEntityOperations {
  use TranslationsHelperTrait;

  /**
   * Saves a translated inline block.
   *
   * @param \Drupal\Core\Entity\EntityInterface $entity
   *   The entity with the layout.
   * @param string $component_uuid
   *   The component UUID.
   * @param array $translated_component_configuration
   *   The translated component configuration.
   * @param bool $new_revision
   *   Whether a new revision of the block should be created.
   */
  protected function saveTranslatedInlineBlock(EntityInterface $entity, $component_uuid, array $translated_component_configuration, $new_revision) {

    /** @var \Drupal\block_content\BlockContentInterface $block */
    $block = unserialize($translated_component_configuration['block_serialized']);

    // Create a InlineBlock plugin from the translated configuration in order to
    // save the block.

    /** @var \Drupal\layout_builder\Plugin\Block\InlineBlock $plugin */
    $plugin = \Drupal::service('plugin.manager.block')
      ->createInstance('inline_block:' . $block
      ->bundle(), $translated_component_configuration);
    $plugin
      ->saveBlockContent($new_revision);

    // Remove serialized block after the block has been saved.
    unset($translated_component_configuration['block_serialized']);

    // Update the block_revision_id in the translated configuration which may
    // have changed after saving the block.
    $configuration = $plugin
      ->getConfiguration();
    $translated_component_configuration['block_revision_id'] = $configuration['block_revision_id'];

    /** @var \Drupal\layout_builder_st\TranslatableSectionStorageInterface $section_storage */
    $section_storage = $this
      ->getSectionStorageForEntity($entity);
    $section_storage
      ->setTranslatedComponentConfiguration($component_uuid, $translated_component_configuration);
  }

  /**
   * {@inheritdoc}
   *
   * Override to ::saveTranslatedInlineBlock() for translations.
   */
  protected function saveInlineBlockComponent(EntityInterface $entity, SectionComponent $component, $new_revision, $duplicate_blocks) {
    $section_storage = $this
      ->getSectionStorageForEntity($entity);
    if (static::isTranslation($section_storage)) {

      /** @var  \Drupal\layout_builder_st\TranslatableSectionStorageInterface $section_storage */
      $translated_component_configuration = $section_storage
        ->getTranslatedComponentConfiguration($component
        ->getUuid());
      if (isset($translated_component_configuration['block_serialized'])) {
        $this
          ->saveTranslatedInlineBlock($entity, $component
          ->getUuid(), $translated_component_configuration, $new_revision);
      }
    }
    else {
      parent::saveInlineBlockComponent($entity, $component, $new_revision, $duplicate_blocks);
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
InlineBlockEntityOperations::$blockContentStorage protected property The block content storage.
InlineBlockEntityOperations::$entityTypeManager protected property The entity type manager.
InlineBlockEntityOperations::$usage protected property Inline block usage tracking service.
InlineBlockEntityOperations::create public static function Instantiates a new instance of this class. Overrides ContainerInjectionInterface::create
InlineBlockEntityOperations::deleteBlocksAndUsage protected function Delete the inline blocks and the usage records.
InlineBlockEntityOperations::getBlockIdsForRevisionIds protected function Gets blocks IDs for an array of revision IDs.
InlineBlockEntityOperations::getPluginBlockId protected function Gets a block ID for an inline block plugin.
InlineBlockEntityOperations::getRemovedBlockIds protected function Gets the IDs of the inline blocks that were removed.
InlineBlockEntityOperations::handleEntityDelete public function Handles entity tracking on deleting a parent entity.
InlineBlockEntityOperations::handlePreSave public function Handles saving a parent entity.
InlineBlockEntityOperations::removeUnused public function Removes unused inline blocks.
InlineBlockEntityOperations::removeUnusedForEntityOnSave protected function Remove all unused inline blocks on save.
InlineBlockEntityOperations::saveInlineBlockComponent protected function Override to ::saveTranslatedInlineBlock() for translations. Overrides InlineBlockEntityOperations::saveInlineBlockComponent
InlineBlockEntityOperations::saveTranslatedInlineBlock protected function Saves a translated inline block.
InlineBlockEntityOperations::__construct public function Constructs a new EntityOperations object.
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
TranslationsHelperTrait::isTranslation protected static function Determines if the sections is for a translation.