You are here

protected function InlineBlockEntityOperations::saveTranslatedInlineBlock in Layout Builder Symmetric Translations 8

Saves a translated inline block.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity with the layout.

string $component_uuid: The component UUID.

array $translated_component_configuration: The translated component configuration.

bool $new_revision: Whether a new revision of the block should be created.

1 call to InlineBlockEntityOperations::saveTranslatedInlineBlock()
InlineBlockEntityOperations::saveInlineBlockComponent in src/InlineBlockEntityOperations.php
Override to ::saveTranslatedInlineBlock() for translations.

File

src/InlineBlockEntityOperations.php, line 28

Class

InlineBlockEntityOperations
Overrides cores InlineBlockEntityOperations to provide translation operations.

Namespace

Drupal\layout_builder_st

Code

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);
}