InlineBlockEntityOperations.php in Layout Builder Symmetric Translations 8
File
src/InlineBlockEntityOperations.php
View source
<?php
namespace Drupal\layout_builder_st;
use Drupal\Core\Entity\EntityInterface;
use Drupal\layout_builder\InlineBlockEntityOperations as CoreInlineBlockEntityOperations;
use Drupal\layout_builder\SectionComponent;
final class InlineBlockEntityOperations extends CoreInlineBlockEntityOperations {
use TranslationsHelperTrait;
protected function saveTranslatedInlineBlock(EntityInterface $entity, $component_uuid, array $translated_component_configuration, $new_revision) {
$block = unserialize($translated_component_configuration['block_serialized']);
$plugin = \Drupal::service('plugin.manager.block')
->createInstance('inline_block:' . $block
->bundle(), $translated_component_configuration);
$plugin
->saveBlockContent($new_revision);
unset($translated_component_configuration['block_serialized']);
$configuration = $plugin
->getConfiguration();
$translated_component_configuration['block_revision_id'] = $configuration['block_revision_id'];
$section_storage = $this
->getSectionStorageForEntity($entity);
$section_storage
->setTranslatedComponentConfiguration($component_uuid, $translated_component_configuration);
}
protected function saveInlineBlockComponent(EntityInterface $entity, SectionComponent $component, $new_revision, $duplicate_blocks) {
$section_storage = $this
->getSectionStorageForEntity($entity);
if (static::isTranslation($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);
}
}
}