You are here

protected function LayoutBuilderDataHandlerTrait::unserializeComponents in Acquia Content Hub 8.2

Prepares Layout Builder components to be unserialized.

Parameters

\Drupal\layout_builder\SectionComponent[] $components: The components to unserialize.

Throws

\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException

\Drupal\Component\Plugin\Exception\PluginNotFoundException

1 call to LayoutBuilderDataHandlerTrait::unserializeComponents()
LayoutBuilderDataHandlerTrait::unserializeSections in src/LayoutBuilder/LayoutBuilderDataHandlerTrait.php
Prepares Layout Builder sections to be unserialized.

File

src/LayoutBuilder/LayoutBuilderDataHandlerTrait.php, line 94

Class

LayoutBuilderDataHandlerTrait
Layout Builder trait for handling data.

Namespace

Drupal\acquia_contenthub\LayoutBuilder

Code

protected function unserializeComponents(array $components) {
  foreach ($components as $component) {
    $plugin = $component
      ->getPlugin();

    // @todo Decide if it's worth to handle this as an event.
    if ($plugin instanceof InlineBlock) {
      $block_uuid = $component
        ->get('block_uuid');
      $entities = $this->entityTypeManager
        ->getStorage('block_content')
        ->loadByProperties([
        'uuid' => $block_uuid,
      ]);
      $entity = array_shift($entities);
      $componentConfiguration = $this
        ->getComponentConfiguration($component);
      $componentConfiguration['block_revision_id'] = $entity
        ->getRevisionId();
      $component
        ->setConfiguration($componentConfiguration);
    }
  }
}