You are here

protected function MigrationDefinitionCreator::setTextFormat in GatherContent 8.5

Set the text format for the text type fields.

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

File

src/MigrationDefinitionCreator.php, line 574

Class

MigrationDefinitionCreator
Create dynamic migration definitions.

Namespace

Drupal\gathercontent

Code

protected function setTextFormat(array &$definition, array $data, string $elementId, string $element, bool $isMultiple) {
  if (isset($data['element_text_formats'][$elementId]) && !empty($data['element_text_formats'][$elementId]) && isset($definition['process'][$element])) {
    if (!$isMultiple) {
      $origElement = $definition['process'][$element];
      unset($definition['process'][$element]);
      $definition['process'][$element . '/format'] = [
        'plugin' => 'default_value',
        'default_value' => $data['element_text_formats'][$elementId],
      ];
      $definition['process'][$element . '/value'] = $origElement;
    }
    else {
      $definition['process'][$element]['process']['format'] = [
        'plugin' => 'default_value',
        'default_value' => $data['element_text_formats'][$elementId],
      ];
    }
    if ($definition['langcode'] != $this->siteDefaultLangCode && $definition['langcode'] != 'und') {
      if (!$isMultiple) {
        $definition['process'][$element . '/value']['language'] = $definition['langcode'];
      }
      else {
        $definition['process'][$element]['process']['language'] = $definition['langcode'];
      }
    }
  }
}