function UserLangcode::transform

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

Overrides ProcessPluginBase::transform

File

core/modules/user/src/Plugin/migrate/process/UserLangcode.php, line 58

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

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