You are here

public function Exporter::processSetAssets in GatherContent 8.5

Set assets.

Parameters

object $field: Field object.

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

bool $isTranslatable: Translatable bool.

string $language: Language string.

string $localFieldName: Field Name.

Return value

array|string Returns value.

Throws

\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException

\Drupal\Component\Plugin\Exception\PluginNotFoundException

1 call to Exporter::processSetAssets()
Exporter::processFields in gathercontent_upload/src/Export/Exporter.php
Processes field data.

File

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

Class

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

Namespace

Drupal\gathercontent_upload\Export

Code

public function processSetAssets(object $field, EntityInterface $entity, bool $isTranslatable, string $language, string $localFieldName) {
  $value = NULL;
  switch ($field->field_type) {
    case 'attachment':

      // Fetch file targets.
      if ($isTranslatable && $entity
        ->hasTranslation($language)) {
        $targets = $entity
          ->getTranslation($language)->{$localFieldName}
          ->getValue();
      }
      else {
        $targets = $entity->{$localFieldName}
          ->getValue();
      }
      $value = [];
      foreach ($targets as $target) {

        /** @var \Drupal\file\FileInterface $file */
        $file = $this->entityTypeManager
          ->getStorage('file')
          ->load($target['target_id']);
        if (empty($file) || !$file
          ->get('gc_file_id')
          ->isEmpty()) {
          continue;
        }
        $value[] = $this->fileSystem
          ->realpath($file
          ->getFileUri());
      }
      $this->collectedFileFields[$field->uuid] = $targets;
      break;
  }
  return $value;
}