function LanguageAddForm::copyFormValuesToEntity
Same name in other branches
- 9 core/modules/language/src/Form/LanguageAddForm.php \Drupal\language\Form\LanguageAddForm::copyFormValuesToEntity()
- 8.9.x core/modules/language/src/Form/LanguageAddForm.php \Drupal\language\Form\LanguageAddForm::copyFormValuesToEntity()
- 10 core/modules/language/src/Form/LanguageAddForm.php \Drupal\language\Form\LanguageAddForm::copyFormValuesToEntity()
Overrides EntityForm::copyFormValuesToEntity
File
-
core/
modules/ language/ src/ Form/ LanguageAddForm.php, line 146
Class
- LanguageAddForm
- Controller for language addition forms.
Namespace
Drupal\language\FormCode
protected function copyFormValuesToEntity(EntityInterface $entity, array $form, FormStateInterface $form_state) {
$langcode = $form_state->getValue('predefined_langcode');
if ($langcode == 'custom') {
$langcode = $form_state->getValue('langcode');
$label = $form_state->getValue('label');
$direction = $form_state->getValue('direction');
}
else {
$standard_languages = LanguageManager::getStandardLanguageList();
$label = $standard_languages[$langcode][0];
$direction = $standard_languages[$langcode][2] ?? ConfigurableLanguage::DIRECTION_LTR;
}
$entity->set('id', $langcode);
$entity->set('label', $label);
$entity->set('direction', $direction);
// There is no weight on the edit form. Fetch all configurable languages
// ordered by weight and set the new language to be placed after them.
$languages = \Drupal::languageManager()->getLanguages(ConfigurableLanguage::STATE_CONFIGURABLE);
$last_language = end($languages);
$entity->setWeight($last_language->getWeight() + 1);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.