You are here

public function UserLangcode::transform in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/user/src/Plugin/migrate/process/UserLangcode.php \Drupal\user\Plugin\migrate\process\UserLangcode::transform()
  2. 10 core/modules/user/src/Plugin/migrate/process/UserLangcode.php \Drupal\user\Plugin\migrate\process\UserLangcode::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/UserLangcode.php, line 60

Class

UserLangcode
Provides a process plugin for the user langcode.

Namespace

Drupal\user\Plugin\migrate\process

Code

public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
  if (!isset($this->configuration['fallback_to_site_default'])) {
    $this->configuration['fallback_to_site_default'] = TRUE;
  }

  // If the user's language is empty, it means the locale module was not
  // installed, so the user's langcode should be English and the user's
  // preferred_langcode and preferred_admin_langcode should fallback to the
  // default language.
  if (empty($value)) {
    if ($this->configuration['fallback_to_site_default']) {
      return $this->languageManager
        ->getDefaultLanguage()
        ->getId();
    }
    else {
      return 'en';
    }
  }
  elseif ($this->languageManager
    ->getLanguage($value) === NULL) {
    return $this->languageManager
      ->getDefaultLanguage()
      ->getId();
  }

  // If the langcode is a valid one, just return it.
  return $value;
}