language_form_alter

language_form_alter(&$form, FormStateInterface $form_state)

Implements hook_form_alter().

File

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

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])) {
      $language_configuration = ContentLanguageSettings::loadByEntityTypeBundle($entity->getEntityTypeId(), $entity->bundle());
      $form[$langcode_key]['#access'] = $language_configuration->isLanguageAlterable();
    }
  }
}
doc_Drupal
2016-10-29 09:23:01
Comments
Leave a Comment

Please login to continue.