You are here

function language_configuration_element_submit in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/language/language.module \language_configuration_element_submit()

Submit handler for the forms that have a language_configuration element.

4 string references to 'language_configuration_element_submit'
BlockContentTypeForm::form in core/modules/block_content/src/BlockContentTypeForm.php
Gets the actual form array to be built.
CommentTypeForm::form in core/modules/comment/src/CommentTypeForm.php
Gets the actual form array to be built.
LanguageConfiguration::processLanguageConfiguration in core/modules/language/src/Element/LanguageConfiguration.php
Process handler for the language_configuration form element.
LanguageConfigurationElement::buildForm in core/modules/language/tests/language_elements_test/src/Form/LanguageConfigurationElement.php
Form constructor.

File

core/modules/language/language.module, line 185
Add language handling functionality to Drupal.

Code

function language_configuration_element_submit(&$form, FormStateInterface $form_state) {

  // 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 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) {

        /** @var EntityFormInterface $form_object */
        $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(array(
        $element_name,
        'langcode',
      )));
      $config
        ->setLanguageAlterable($form_state
        ->getValue(array(
        $element_name,
        'language_alterable',
      )));
      $config
        ->save();

      // Set the form_state languaged with the updated bundle.
      $form_state
        ->set('language', $language);
    }
  }
}