function ProfileFieldOptionTranslation::transform

Same name in other branches
  1. 9 core/modules/user/src/Plugin/migrate/process/d6/ProfileFieldOptionTranslation.php \Drupal\user\Plugin\migrate\process\d6\ProfileFieldOptionTranslation::transform()
  2. 10 core/modules/user/src/Plugin/migrate/process/d6/ProfileFieldOptionTranslation.php \Drupal\user\Plugin\migrate\process\d6\ProfileFieldOptionTranslation::transform()
  3. 11.x core/modules/user/src/Plugin/migrate/process/d6/ProfileFieldOptionTranslation.php \Drupal\user\Plugin\migrate\process\d6\ProfileFieldOptionTranslation::transform()

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;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.