You are here

protected function MigrationDefinitionCreator::setTextFieldDefinition in GatherContent 8.5

Set the text definition. Set concatenation if needed.

1 call to MigrationDefinitionCreator::setTextFieldDefinition()
MigrationDefinitionCreator::setFieldDefinition in src/MigrationDefinitionCreator.php
Set field definition.

File

src/MigrationDefinitionCreator.php, line 613

Class

MigrationDefinitionCreator
Create dynamic migration definitions.

Namespace

Drupal\gathercontent

Code

protected function setTextFieldDefinition(array &$definition, string $element, string $elementId, bool $isMultiple) {

  // Check if the field has a /value element to support different formats.
  $key = $element . '/value';
  if (!isset($definition['process'][$key])) {
    $key = $element;
  }
  if (isset($definition['process'][$key])) {
    if (!$isMultiple) {
      $definition['process'][$key]['plugin'] = 'concat';
      if (!is_array($definition['process'][$key]['source'])) {
        $definition['process'][$key]['source'] = [
          $definition['process'][$key]['source'],
        ];
      }
      $definition['process'][$key]['source'][] = $elementId;
      $definition['process'][$key]['delimiter'] = ' ';
    }
    else {
      $concatFieldName = 'concat_' . $element;
      if (!array_key_exists($concatFieldName, $definition['process'])) {
        $concatElement[$concatFieldName] = [
          'plugin' => 'gather_content_concat',
          'source' => [
            $definition['process'][$element]['source'],
          ],
          'delimiter' => ' ',
        ];
        $definition['process'] = $concatElement + $definition['process'];
        $definition['process'][$element]['source'] = '@' . $concatFieldName;
      }
      $definition['process'][$concatFieldName]['source'][] = $elementId;
    }
    return;
  }
  if ($isMultiple) {
    $definition['process'][$element] = [
      'plugin' => 'gather_content_sub_process',
      'source' => $elementId,
      'process' => [
        'value' => 'value',
      ],
    ];
  }
  else {
    $definition['process'][$element] = [
      'plugin' => 'gather_content_get',
      'source' => $elementId,
    ];
  }
}