You are here

public function Exporter::processGroups in GatherContent 8.5

Manages the panes and changes the Item object values.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: Entity object.

\Drupal\gathercontent\Entity\MappingInterface $mapping: Mappig object.

Return value

array Returns Content array.

Throws

\Exception

1 call to Exporter::processGroups()
Exporter::export in gathercontent_upload/src/Export/Exporter.php
Exports the changes made in Drupal contents.

File

gathercontent_upload/src/Export/Exporter.php, line 229

Class

Exporter
Class for handling import/update logic from GatherContent to Drupal.

Namespace

Drupal\gathercontent_upload\Export

Code

public function processGroups(EntityInterface $entity, MappingInterface $mapping) {
  $mappingData = unserialize($mapping
    ->getData());
  if (empty($mappingData)) {
    throw new Exception("Mapping data is empty.");
  }
  $templateData = unserialize($mapping
    ->getTemplate());
  $data = [
    'content' => [],
    'assets' => [],
  ];
  foreach ($templateData->related->structure->groups as $group) {
    $isTranslatable = $this->moduleHandler
      ->moduleExists('content_translation') && $this->contentTranslation
      ->isEnabled($mapping
      ->getMappedEntityType(), $mapping
      ->getContentType()) && isset($mappingData[$group->uuid]['language']) && $mappingData[$group->uuid]['language'] != Language::LANGCODE_NOT_SPECIFIED;
    if ($isTranslatable) {
      $language = $mappingData[$group->uuid]['language'];
    }
    else {
      $language = Language::LANGCODE_NOT_SPECIFIED;
    }
    $fields = $this
      ->processFields($group, $entity, $mappingData, $isTranslatable, $language);
    $data['content'] += $fields['content'];
    $data['assets'] += $fields['assets'];
  }
  return $data;
}