You are here

public function DefaultLayoutBuilderHandler::pull in CMS Content Sync 8

Same name and namespace in other branches
  1. 2.1.x src/Plugin/cms_content_sync/field_handler/DefaultLayoutBuilderHandler.php \Drupal\cms_content_sync\Plugin\cms_content_sync\field_handler\DefaultLayoutBuilderHandler::pull()
  2. 2.0.x src/Plugin/cms_content_sync/field_handler/DefaultLayoutBuilderHandler.php \Drupal\cms_content_sync\Plugin\cms_content_sync\field_handler\DefaultLayoutBuilderHandler::pull()

Parameters

\Drupal\cms_content_sync\SyncIntent $intent: The request containing all pushed data

Return value

bool Whether or not the content has been pulled. FALSE is a desired state, meaning the entity should not be pulled according to config.

Throws

\Drupal\cms_content_sync\Exception\SyncException

Overrides FieldHandlerBase::pull

File

src/Plugin/cms_content_sync/field_handler/DefaultLayoutBuilderHandler.php, line 97

Class

DefaultLayoutBuilderHandler
Providing a minimalistic implementation for any field type.

Namespace

Drupal\cms_content_sync\Plugin\cms_content_sync\field_handler

Code

public function pull(PullIntent $intent) {
  $layout_builder_array = $intent
    ->getProperty($this->fieldName);
  if (!empty($layout_builder_array)) {
    $layout_builder_elements = [];
    foreach ($layout_builder_array as $key => $layout_builder_element) {
      if (isset($layout_builder_element['components'])) {
        foreach ($layout_builder_element['components'] as $uuid => $component) {
          if (isset($component['configuration']['provider'])) {
            if ('layout_builder' == $component['configuration']['provider']) {
              if (isset($component['configuration']['block_reference'])) {
                $block = $intent
                  ->loadEmbeddedEntity($component['configuration']['block_reference']);
                if ($block) {
                  $layout_builder_element['components'][$uuid]['configuration']['block_revision_id'] = $block
                    ->get('revision_id')->value;
                }
              }
            }
          }
        }
      }
      $layout_builder_elements[$key]['section'] = Section::fromArray($layout_builder_element);
    }
    $intent
      ->getEntity()
      ->set($this->fieldName, $layout_builder_elements);
  }
}