function LanguageConfiguration::submit
Same name and namespace in other branches
- main core/modules/language/src/Element/LanguageConfiguration.php \Drupal\language\Element\LanguageConfiguration::submit()
Submit handler for the forms that have a language_configuration element.
Parameters
array $form: The form render array.
\Drupal\Core\Form\FormStateInterface $form_state: The form state instance.
1 call to LanguageConfiguration::submit()
- language_configuration_element_submit in core/
modules/ language/ language.module - Submit handler for the forms that have a language_configuration element.
File
-
core/
modules/ language/ src/ Element/ LanguageConfiguration.php, line 96
Class
- LanguageConfiguration
- Defines an element for language configuration for a single field.
Namespace
Drupal\language\ElementCode
public static function submit(array &$form, FormStateInterface $form_state) : void {
// Iterate through all the language_configuration elements and save their
// values. In case we are editing a bundle, we must check the new bundle
// name, because, e.g., hook_ENTITY_update has been fired before.
if ($language = $form_state->get('language')) {
foreach ($language as $element_name => $values) {
$entity_type_id = $values['entity_type'];
$bundle = $values['bundle'];
$form_object = $form_state->getFormObject();
if ($form_object instanceof EntityFormInterface) {
$entity = $form_object->getEntity();
if ($entity->getEntityType()
->getBundleOf()) {
$bundle = $entity->id();
$language[$element_name]['bundle'] = $bundle;
}
}
$config = ContentLanguageSettings::loadByEntityTypeBundle($entity_type_id, $bundle);
$config->setDefaultLangcode($form_state->getValue([
$element_name,
'langcode',
]));
$config->setLanguageAlterable($form_state->getValue([
$element_name,
'language_alterable',
]));
$config->save();
// Set the form_state language with the updated bundle.
$form_state->set('language', $language);
}
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.