function language_form_alter
Same name in other branches
- 9 core/modules/language/language.module \language_form_alter()
- 8.9.x core/modules/language/language.module \language_form_alter()
- 10 core/modules/language/language.module \language_form_alter()
Implements hook_form_alter().
File
-
core/
modules/ language/ language.module, line 373
Code
function language_form_alter(&$form, FormStateInterface $form_state) {
// Content entity forms may have added a langcode field. But content language
// configuration should decide if it should be exposed or not in the forms.
$form_object = $form_state->getFormObject();
if ($form_object instanceof ContentEntityFormInterface && $form_object->getEntity()
->getEntityType()
->hasKey('langcode')) {
/** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
$entity = $form_object->getEntity();
$entity_type = $entity->getEntityType();
$langcode_key = $entity_type->getKey('langcode');
if (isset($form[$langcode_key]) && $form[$langcode_key]['#access'] !== FALSE) {
$language_configuration = ContentLanguageSettings::loadByEntityTypeBundle($entity->getEntityTypeId(), $entity->bundle());
$form[$langcode_key]['#access'] = $language_configuration->isLanguageAlterable();
}
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.