You are here

public function BlockFieldBlockContentImporter::importBlockContentEntities in Entity Share 8.2

Import block contents from block field.

Parameters

\Drupal\entity_share_client\Event\EntityListDataAlterEvent $event: The event containing the entity list data.

File

modules/entity_share_client/src/EventSubscriber/BlockFieldBlockContentImporter.php, line 78

Class

BlockFieldBlockContentImporter
Class BlockFieldBlockContentImporter.

Namespace

Drupal\entity_share_client\EventSubscriber

Code

public function importBlockContentEntities(EntityListDataAlterEvent $event) {
  $remote = $event
    ->getRemote();
  $http_client = $this->remoteManager
    ->prepareJsonApiClient($remote);
  $entity_list_data = $event
    ->getEntityListData();
  $entity_list_data = EntityShareUtility::prepareData($entity_list_data);

  // Parse entity list data to extract urls to get block content from block
  // field. And remove this info.
  foreach ($entity_list_data as $key => $entity_data) {
    if (isset($entity_data['attributes']) && is_array($entity_data['attributes'])) {
      foreach ($entity_data['attributes'] as $field_name => $field_data) {
        if (is_array($field_data)) {
          if (EntityShareUtility::isNumericArray($field_data)) {
            foreach ($field_data as $delta => $value) {
              if (isset($value['block_content_href'])) {
                $this
                  ->importBlockContent($http_client, $value['block_content_href']);
                unset($entity_list_data[$key]['attributes'][$field_name][$delta]['block_content_href']);
              }
            }
          }
          elseif (isset($field_data['block_content_href'])) {
            $this
              ->importBlockContent($http_client, $field_data['block_content_href']);
            unset($entity_list_data[$key]['attributes'][$field_name]['block_content_href']);
          }
        }
      }
    }
  }
  $event
    ->setEntityListData($entity_list_data);
}