protected function LanguageAddForm::copyFormValuesToEntity in Drupal 8
Same name and namespace in other branches
- 9 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()
Copies top-level form values to entity properties
This should not change existing entity properties that are not being edited by this form.
Parameters
\Drupal\Core\Entity\EntityInterface $entity: The entity the current form should operate upon.
array $form: A nested array of form elements comprising the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
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 = isset($standard_languages[$langcode][2]) ? $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);
}