protected LanguageAddForm::copyFormValuesToEntity(EntityInterface $entity, array $form, FormStateInterface $form_state)
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 143
Class
- LanguageAddForm
- Controller for language addition forms.
Namespace
Drupal\language\Form
Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | 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); } |
Please login to continue.