You are here

public function ProfileFieldOptionTranslation::transform in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/user/src/Plugin/migrate/process/d6/ProfileFieldOptionTranslation.php \Drupal\user\Plugin\migrate\process\d6\ProfileFieldOptionTranslation::transform()

Performs the associated process.

Parameters

mixed $value: The value to be transformed.

\Drupal\migrate\MigrateExecutableInterface $migrate_executable: The migration in which this process is being executed.

\Drupal\migrate\Row $row: The row from the source to process. Normally, just transforming the value is adequate but very rarely you might need to change two columns at the same time or something like that.

string $destination_property: The destination property currently worked on. This is only used together with the $row above.

Return value

string|array The newly transformed value.

Overrides ProcessPluginBase::transform

File

core/modules/user/src/Plugin/migrate/process/d6/ProfileFieldOptionTranslation.php, line 22

Class

ProfileFieldOptionTranslation
Determines the settings property and translation.

Namespace

Drupal\user\Plugin\migrate\process\d6

Code

public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
  list($field_type, $translation) = $value;
  $new_value = NULL;
  if (isset($translation)) {
    $allowed_values = [];
    $list = explode("\n", $translation);
    $list = array_map('trim', $list);
    $list = array_filter($list, 'strlen');
    if ($field_type === 'list_string') {
      foreach ($list as $key => $value) {
        $allowed_values[] = [
          'label' => $value,
        ];
      }
    }
    $new_value = [
      'settings.allowed_values',
      $allowed_values,
    ];
  }
  return $new_value;
}