function LanguageHooks::formAlter
Implements hook_form_alter().
File
-
core/
modules/ language/ src/ Hook/ LanguageHooks.php, line 273
Class
- LanguageHooks
- Hook implementations for language.
Namespace
Drupal\language\HookCode
public function formAlter(&$form, FormStateInterface $form_state) : void {
// 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.