diff --git a/core/modules/comment/src/CommentForm.php b/core/modules/comment/src/CommentForm.php index bf81415..cc8b9d4 100644 --- a/core/modules/comment/src/CommentForm.php +++ b/core/modules/comment/src/CommentForm.php @@ -17,6 +17,7 @@ use Drupal\Core\Language\Language; use Drupal\Core\Language\LanguageInterface; use Drupal\Core\Session\AccountInterface; +use Drupal\language\Entity\ContentLanguageSettings; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -161,13 +162,12 @@ public function form(array $form, FormStateInterface $form_state) { $form['author']['name']['#attributes']['data-drupal-default-value'] = $this->config('user.settings')->get('anonymous'); } - $language_configuration = \Drupal::moduleHandler()->invoke('language', 'get_default_configuration', array('comment', $comment->getTypeId())); $form['langcode'] = array( '#title' => t('Language'), '#type' => 'language_select', '#default_value' => $comment->getUntranslated()->language()->getId(), '#languages' => Language::STATE_ALL, - '#access' => isset($language_configuration['language_alterable']) && $language_configuration['language_alterable'], + '#access' => FALSE, ); // Add author email and homepage fields depending on the current user. diff --git a/core/modules/contact/src/MessageForm.php b/core/modules/contact/src/MessageForm.php index 41c7f37..a84fb8e 100644 --- a/core/modules/contact/src/MessageForm.php +++ b/core/modules/contact/src/MessageForm.php @@ -98,13 +98,12 @@ public function form(array $form, FormStateInterface $form_state) { $form['preview']['message'] = $this->entityManager->getViewBuilder('contact_message')->view($message, 'full'); } - $language_configuration = $this->moduleHandler->invoke('language', 'get_default_configuration', array('contact_message', $message->getContactForm()->id())); $form['langcode'] = array( '#title' => $this->t('Language'), '#type' => 'language_select', '#default_value' => $message->getUntranslated()->language()->getId(), '#languages' => Language::STATE_ALL, - '#access' => isset($language_configuration['language_alterable']) && $language_configuration['language_alterable'], + '#access' => FALSE, ); $form['name'] = array( diff --git a/core/modules/language/language.module b/core/modules/language/language.module index fd51ff4..6f69899 100644 --- a/core/modules/language/language.module +++ b/core/modules/language/language.module @@ -6,6 +6,7 @@ */ use Drupal\Component\Utility\String; +use Drupal\Core\Entity\ContentEntityForm; use Drupal\Core\Entity\EntityFormInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Language\LanguageInterface; @@ -493,6 +494,19 @@ function language_form_system_regional_settings_alter(&$form, FormStateInterface } /** + * Implements hook_form_alter(). + */ +function language_form_alter(&$form, FormStateInterface $form_state, $form_id) { + $form_object = $form_state->getFormObject(); + if ($form_object instanceof ContentEntityForm && isset($form['langcode'])) { + $entity_type_id = $form_object->getEntity()->getEntityTypeId(); + $bundle = $form_object->getEntity()->bundle(); + $language_configuration = ContentLanguageSettings::loadByEntityTypeBundle($entity_type_id, $bundle); + $form['langcode']['#access'] = $language_configuration->isLanguageAlterable(); + } +} + +/** * Form submission handler for system_regional_settings(). * * @see language_form_system_regional_settings_alter() diff --git a/core/modules/menu_link_content/src/Form/MenuLinkContentForm.php b/core/modules/menu_link_content/src/Form/MenuLinkContentForm.php index a9d4da1..d67c5d1 100644 --- a/core/modules/menu_link_content/src/Form/MenuLinkContentForm.php +++ b/core/modules/menu_link_content/src/Form/MenuLinkContentForm.php @@ -257,19 +257,12 @@ public function form(array $form, FormStateInterface $form_state) { '#weight' => -2, ); - $language_configuration = $this->moduleHandler->invoke('language', 'get_default_configuration', array('menu_link_content', 'menu_link_content')); - if ($this->entity->isNew()) { - $default_language = isset($language_configuration['langcode']) ? $language_configuration['langcode'] : $this->languageManager->getDefaultLanguage()->getId(); - } - else { - $default_language = $this->entity->getUntranslated()->language()->getId(); - } $form['langcode'] = array( '#title' => t('Language'), '#type' => 'language_select', - '#default_value' => $default_language, + '#default_value' => $this->entity->getUntranslated()->language()->getId(), '#languages' => Language::STATE_ALL, - '#access' => !empty($language_configuration['language_alterable']), + '#access' => FALSE, ); $default = $this->entity->getMenuName() . ':' . $this->entity->getParentId(); diff --git a/core/modules/node/src/NodeForm.php b/core/modules/node/src/NodeForm.php index 8114d34..f9fb2ee 100644 --- a/core/modules/node/src/NodeForm.php +++ b/core/modules/node/src/NodeForm.php @@ -109,18 +109,12 @@ public function form(array $form, FormStateInterface $form_state) { '#default_value' => $node->getChangedTime(), ); - $is_language_alterable = false; - if ($this->moduleHandler->moduleExists('language')) { - $language_configuration = ContentLanguageSettings::loadByEntityTypeBundle('node', $node->getType()); - $is_language_alterable = $language_configuration->isLanguageAlterable(); - } - $form['langcode'] = array( '#title' => t('Language'), '#type' => 'language_select', '#default_value' => $node->getUntranslated()->language()->getId(), '#languages' => LanguageInterface::STATE_ALL, - '#access' => $is_language_alterable, + '#access' => FALSE, ); $form['advanced'] = array( diff --git a/core/modules/taxonomy/src/TermForm.php b/core/modules/taxonomy/src/TermForm.php index 47291f8..b10bccb 100644 --- a/core/modules/taxonomy/src/TermForm.php +++ b/core/modules/taxonomy/src/TermForm.php @@ -29,17 +29,12 @@ public function form(array $form, FormStateInterface $form_state) { $form_state->set(['taxonomy', 'parent'], $parent); $form_state->set(['taxonomy', 'vocabulary'], $vocabulary); - $is_language_alterable = false; - if ($this->moduleHandler->moduleExists('language')) { - $language_configuration = ContentLanguageSettings::loadByEntityTypeBundle('taxonomy_term', $vocabulary->id()); - $is_language_alterable = $language_configuration->isLanguageAlterable(); - } $form['langcode'] = array( '#type' => 'language_select', '#title' => $this->t('Language'), '#languages' => LanguageInterface::STATE_ALL, '#default_value' => $term->getUntranslated()->language()->getId(), - '#access' => $is_language_alterable, + '#access' => FALSE, ); $form['relations'] = array(