Upgraded drupal core with security updates
[yaffs-website] / web / core / modules / language / language.module
1 <?php
2
3 /**
4  * @file
5  * Add language handling functionality to Drupal.
6  */
7
8 use Drupal\Core\Access\AccessResult;
9 use Drupal\Core\Entity\ContentEntityFormInterface;
10 use Drupal\Core\Entity\EntityFormInterface;
11 use Drupal\Core\Entity\EntityInterface;
12 use Drupal\Core\Field\FieldDefinitionInterface;
13 use Drupal\Core\Field\FieldItemListInterface;
14 use Drupal\Core\Form\FormStateInterface;
15 use Drupal\Core\Language\LanguageInterface;
16 use Drupal\Core\Routing\RouteMatchInterface;
17 use Drupal\Core\Session\AccountInterface;
18 use Drupal\language\ConfigurableLanguageInterface;
19 use Drupal\language\Entity\ContentLanguageSettings;
20 use Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationUI;
21 use Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationUrl;
22 use Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationUrlFallback;
23
24 /**
25  * Implements hook_help().
26  */
27 function language_help($route_name, RouteMatchInterface $route_match) {
28   switch ($route_name) {
29     case 'help.page.language':
30       $output = '';
31       $output .= '<h3>' . t('About') . '</h3>';
32       $output .= '<p>' . t('The Language module allows you to configure the languages used on your site, and provides information for the <a href=":content">Content Translation</a>, <a href=":interface">Interface Translation</a>, and <a href=":configuration">Configuration Translation</a> modules, if they are enabled. For more information, see the <a href=":doc_url">online documentation for the Language module</a>.', [':doc_url' => 'https://www.drupal.org/documentation/modules/language', ':content' => (\Drupal::moduleHandler()->moduleExists('content_translation')) ? \Drupal::url('help.page', ['name' => 'content_translation']) : '#', ':interface' => (\Drupal::moduleHandler()->moduleExists('locale')) ? \Drupal::url('help.page', ['name' => 'locale']) : '#', ':configuration' => (\Drupal::moduleHandler()->moduleExists('config_translation')) ? \Drupal::url('help.page', ['name' => 'config_translation']) : '#']) . '</p>';
33       $output .= '<h3>' . t('Uses') . '</h3>';
34       $output .= '<dl>';
35       $output .= '<dt>' . t('Adding languages') . '</dt>';
36       $output .= '<dd>' . t('You can add languages on the <a href=":language_list">Languages</a> page by selecting <em>Add language</em> and choosing a language from the drop-down menu. This language is then displayed in the languages list, where it can be configured further. If the <a href=":interface">Interface translation module</a> is enabled, and the <em>translation server</em> is set as a translation source, then the interface translation for this language is automatically downloaded as well.', [':language_list' => \Drupal::url('entity.configurable_language.collection'), ':interface' => (\Drupal::moduleHandler()->moduleExists('locale')) ? \Drupal::url('help.page', ['name' => 'locale']) : '#']) . '</dd>';
37       $output .= '<dt>' . t('Adding custom languages') . '</dt>';
38       $output .= '<dd>' . t('You can add a language that is not provided in the drop-down list by choosing <em>Custom language</em> at the end of the list. You then have to configure its language code, name, and direction in the form provided.') . '</dd>';
39       $output .= '<dt>' . t('Configuring content languages') . '</dt>';
40       $output .= '<dd>' . t('By default, content is created in the site\'s default language and no language selector is displayed on content creation pages. On the <a href=":content_language">Content language</a> page you can customize the language configuration for any supported content entity on your site (for example for content types or menu links). After choosing an entity, you are provided with a drop-down menu to set the default language and a check-box to display language selectors.', [':content_language' => \Drupal::url('language.content_settings_page')]) . '</dd>';
41       $output .= '<dt>' . t('Adding a language switcher block') . '</dt>';
42       $output .= '<dd>' . t('If the Block module is enabled, then you can add a language switcher block on the <a href=":blocks">Block layout</a> page to allow users to switch between languages.', [':blocks' => (\Drupal::moduleHandler()->moduleExists('block')) ? \Drupal::url('block.admin_display') : '#']) . '</dd>';
43       $output .= '<dt>' . t('Making a block visible per language') . '</dt>';
44       $output .= '<dd>' . t('If the Block module is enabled, then the Language module allows you to set the visibility of a block based on selected languages on the <a href=":blocks">Block layout</a> page.', [':blocks' => (\Drupal::moduleHandler()->moduleExists('block')) ? \Drupal::url('block.admin_display') : '#']) . '</dd>';
45       $output .= '<dt>' . t('Choosing user languages') . '</dt>';
46       $output .= '<dd>' . t('Users can choose a <em>Site language</em> on their profile page. This language is used for email messages, and can be used by modules to determine a user\'s language. It can also be used for interface text, if the <em>User</em> method is enabled as a <em>Detection and selection</em> method (see below). Administrative users can choose a separate <em>Administration pages language</em> for the interface text on administration pages. This configuration is only available on the user\'s profile page if the <em>Account administration pages</em> method is enabled (see below).') . '</dd>';
47       $output .= '<dt>' . t('Language detection and selection') . '</dt>';
48       $output .= '<dd>' . t('The <a href=":detection">Detection and selection</a> page provides several methods for deciding which language is used for displaying interface text. When a method detects and selects an interface language, then the following methods in the list are not applied. You can order them by importance, with your preferred method at the top of the list, followed by one or several fall-back methods.', [':detection' => \Drupal::url('language.negotiation')]);
49       $output .= '<ul><li>' . t('<em>URL</em> sets the interface language based on a path prefix or domain (for example specifying <em>de</em> for German would result in URLs like <em>example.com/de/contact</em>). The default language does not require a path prefix, but can have one assigned as well. If the language detection is done by domain name, a domain needs to be specified for each language.') . '</li>';
50       $output .= '<li>' . t('<em>Session</em> determines the interface language from a request or session parameter (for example <em>example.com?language=de</em> would set the interface language to German based on the use of <em>de</em> as the <em>language</em> parameter).') . '</li>';
51       $output .= '<li>' . t('<em>User</em> follows the language configuration set on the user\'s profile page.') . '</li>';
52       $output .= '<li>' . t('<em>Browser</em> sets the interface language based on the browser\'s language settings. Since browsers use different language codes to refer to the same languages, you can add and edit languages codes to map the browser language codes to the <a href=":language_list">language codes</a> used on your site.', [':language_list' => \Drupal::url('entity.configurable_language.collection')]) . '</li>';
53       $output .= '<li>' . t('<em>Account administration pages</em> follows the configuration set as <em>Administration pages language</em> on the profile page of an administrative user. This method is similar to the <em>User</em> method, but only sets the interface text language on administration pages, independent of the interface text language on other pages.') . '</li>';
54       $output .= '<li>' . t('<em>Selected language</em> allows you to specify the site\'s default language or a specific language as the fall-back language. This method should be listed last.') . '</li></ul></dd>';
55       $output .= '</dl>';
56       return $output;
57
58     case 'entity.configurable_language.collection':
59       $output = '<p>' . t('Reorder the configured languages to set their order in the language switcher block and, when editing content, in the list of selectable languages. This ordering does not impact <a href=":detection">detection and selection</a>.', [':detection' => \Drupal::url('language.negotiation')]) . '</p>';
60       $output .= '<p>' . t('The site default language can also be set. It is not recommended to change the default language on a working site. <a href=":language-detection">Configure the Selected language</a> setting on the detection and selection page to change the fallback language for language selection.', [':language-detection' => \Drupal::url('language.negotiation')]) . '</p>';
61       return $output;
62
63     case 'language.add':
64       return '<p>' . t('Add a language to be supported by your site. If your desired language is not available, pick <em>Custom language...</em> at the end and provide a language code and other details manually.') . '</p>';
65
66     case 'language.negotiation':
67       $output = '<p>' . t('Define how to decide which language is used to display page elements (primarily text provided by modules, such as field labels and help text). This decision is made by evaluating a series of detection methods for languages; the first detection method that gets a result will determine which language is used for that type of text. Be aware that some language detection methods are unreliable under certain conditions, such as browser detection when page-caching is enabled and a user is not currently logged in. Define the order of evaluation of language detection methods on this page. The default language can be changed in the <a href=":admin-change-language">list of languages</a>.', [':admin-change-language' => \Drupal::url('entity.configurable_language.collection')]) . '</p>';
68       return $output;
69
70     case 'language.negotiation_session':
71       $output = '<p>' . t('Determine the language from a request/session parameter. Example: "http://example.com?language=de" sets language to German based on the use of "de" within the "language" parameter.') . '</p>';
72       return $output;
73
74     case 'language.negotiation_browser':
75       $output = '<p>' . t('Browsers use different language codes to refer to the same languages. Internally, a best effort is made to determine the correct language based on the code that the browser sends. You can add and edit additional mappings from browser language codes to <a href=":configure-languages">site languages</a>.', [':configure-languages' => \Drupal::url('entity.configurable_language.collection')]) . '</p>';
76       return $output;
77
78     case 'language.negotiation_selected':
79       $output = '<p>' . t('Changing the selected language here (and leaving this option as the last among the detection and selection options) is the easiest way to change the fallback language for the website, if you need to change how your site works by default (e.g., when using an empty path prefix or using the default domain). <a href=":admin-change-language">Changing the site\'s default language</a> itself might have other undesired side effects.', [':admin-change-language' => \Drupal::url('entity.configurable_language.collection')]) . '</p>';
80       return $output;
81
82     case 'entity.block.edit_form':
83       if (($block = $route_match->getParameter('block')) && $block->getPluginId() == 'language_block:language_interface') {
84         return '<p>' . t('With multiple languages configured, registered users can select their preferred language and authors can assign a specific language to content.') . '</p>';
85       }
86       break;
87
88     case 'block.admin_add':
89       if ($route_match->getParameter('plugin_id') == 'language_block:language_interface') {
90         return '<p>' . t('With multiple languages configured, registered users can select their preferred language and authors can assign a specific language to content.') . '</p>';
91       }
92       break;
93
94     case 'language.content_settings_page':
95       return '<p>' . t("Change language settings for <em>content types</em>, <em>taxonomy vocabularies</em>, <em>user profiles</em>, or any other supported element on your site. By default, language settings hide the language selector and the language is the site's default language.") . '</p>';
96   }
97 }
98
99 /**
100  * Implements hook_theme().
101  */
102 function language_theme() {
103   return [
104     'language_negotiation_configure_form' => [
105       'render element' => 'form',
106       'file' => 'language.admin.inc',
107     ],
108     'language_content_settings_table' => [
109       'render element' => 'element',
110       'file' => 'language.admin.inc',
111     ],
112   ];
113 }
114
115 /**
116  * Implements hook_element_info_alter().
117  *
118  * @see \Drupal\Core\Render\Element\LanguageSelect
119  * @see \Drupal\Core\Render\Element\Select
120  */
121 function language_element_info_alter(&$type) {
122   // Alter the language_select element so that it will be rendered like a select
123   // field.
124   if (isset($type['language_select'])) {
125     if (!isset($type['language_select']['#process'])) {
126       $type['language_select']['#process'] = [];
127     }
128     if (!isset($type['language_select']['#theme_wrappers'])) {
129       $type['language_select']['#theme_wrappers'] = [];
130     }
131     $type['language_select']['#process'] = array_merge($type['language_select']['#process'], [
132       'language_process_language_select',
133       ['Drupal\Core\Render\Element\Select', 'processSelect'],
134       ['Drupal\Core\Render\Element\RenderElement', 'processAjaxForm'],
135     ]);
136     $type['language_select']['#theme'] = 'select';
137     $type['language_select']['#theme_wrappers'] = array_merge($type['language_select']['#theme_wrappers'], ['form_element']);
138     $type['language_select']['#languages'] = LanguageInterface::STATE_CONFIGURABLE;
139     $type['language_select']['#multiple'] = FALSE;
140   }
141 }
142
143 /**
144  * Processes a language select list form element.
145  *
146  * @param array $element
147  *   The form element to process.
148  *
149  * @return array
150  *   The processed form element.
151  */
152 function language_process_language_select($element) {
153   // Don't set the options if another module (translation for example) already
154   // set the options.
155   if (!isset($element['#options'])) {
156     $element['#options'] = [];
157     foreach (\Drupal::languageManager()->getLanguages($element['#languages']) as $langcode => $language) {
158       $element['#options'][$langcode] = $language->isLocked() ? t('- @name -', ['@name' => $language->getName()]) : $language->getName();
159     }
160   }
161   return $element;
162 }
163
164 /**
165  * Implements hook_entity_base_field_info_alter().
166  */
167 function language_entity_base_field_info_alter(&$fields) {
168   foreach ($fields as $definition) {
169     // Set configurable form display for language fields with display options.
170     if ($definition->getType() == 'language') {
171       foreach (['form', 'view'] as $type) {
172         if ($definition->getDisplayOptions($type)) {
173           // The related configurations will be purged manually on Language
174           // module uninstallation. @see language_modules_uninstalled().
175           $definition->setDisplayConfigurable($type, TRUE);
176         }
177       }
178     }
179   }
180 }
181
182 /**
183  * Submit handler for the forms that have a language_configuration element.
184  */
185 function language_configuration_element_submit(&$form, FormStateInterface $form_state) {
186   // Iterate through all the language_configuration elements and save their
187   // values.
188   // In case we are editing a bundle, we must check the new bundle name,
189   // because e.g. hook_ENTITY_update fired before.
190   if ($language = $form_state->get('language')) {
191     foreach ($language as $element_name => $values) {
192       $entity_type_id = $values['entity_type'];
193       $bundle = $values['bundle'];
194       $form_object = $form_state->getFormObject();
195       if ($form_object instanceof EntityFormInterface) {
196         /** @var EntityFormInterface $form_object */
197         $entity = $form_object->getEntity();
198         if ($entity->getEntityType()->getBundleOf()) {
199           $bundle = $entity->id();
200           $language[$element_name]['bundle'] = $bundle;
201         }
202       }
203       $config = ContentLanguageSettings::loadByEntityTypeBundle($entity_type_id, $bundle);
204       $config->setDefaultLangcode($form_state->getValue([$element_name, 'langcode']));
205       $config->setLanguageAlterable($form_state->getValue([$element_name, 'language_alterable']));
206       $config->save();
207
208       // Set the form_state languaged with the updated bundle.
209       $form_state->set('language', $language);
210     }
211   }
212 }
213
214 /**
215  * Implements hook_entity_bundle_delete().
216  */
217 function language_entity_bundle_delete($entity_type_id, $bundle) {
218   // Remove the content language settings associated with the bundle.
219   $settings = ContentLanguageSettings::loadByEntityTypeBundle($entity_type_id, $bundle);
220   if (!$settings->isNew()) {
221     $settings->delete();
222   }
223 }
224
225 /**
226  * Returns the default language code assigned to an entity type and a bundle.
227  *
228  * @param string $entity_type
229  *   The entity type.
230  * @param string $bundle
231  *   The bundle name.
232  *
233  * @return string
234  *   The language code.
235  */
236 function language_get_default_langcode($entity_type, $bundle) {
237   $configuration = ContentLanguageSettings::loadByEntityTypeBundle($entity_type, $bundle);
238
239   $default_value = NULL;
240   $language_interface = \Drupal::languageManager()->getCurrentLanguage();
241   switch ($configuration->getDefaultLangcode()) {
242     case LanguageInterface::LANGCODE_SITE_DEFAULT:
243       $default_value = \Drupal::languageManager()->getDefaultLanguage()->getId();
244       break;
245
246     case 'current_interface':
247       $default_value = $language_interface->getId();
248       break;
249
250     case 'authors_default':
251       $user = \Drupal::currentUser();
252       $language_code = $user->getPreferredLangcode();
253       if (!empty($language_code)) {
254         $default_value = $language_code;
255       }
256       else {
257         $default_value = $language_interface->getId();
258       }
259       break;
260   }
261   if ($default_value) {
262     return $default_value;
263   }
264
265   // If we still do not have a default value, just return the value stored in
266   // the configuration; it has to be an actual language code.
267   return $configuration->getDefaultLangcode();
268 }
269
270 /**
271  * Reads language prefixes and uses the langcode if no prefix is set.
272  *
273  * @deprecated in Drupal 8.0.x-dev, will be removed before Drupal 9.0.0.
274  *   Use \Drupal::config('language.negotiation')->get('url.prefixes') instead.
275  */
276 function language_negotiation_url_prefixes() {
277   return \Drupal::config('language.negotiation')->get('url.prefixes');
278 }
279
280 /**
281  * Update the list of prefixes from the installed languages.
282  */
283 function language_negotiation_url_prefixes_update() {
284   $config = \Drupal::configFactory()->getEditable('language.negotiation');
285   $prefixes = $config->get('url.prefixes');
286   foreach (\Drupal::languageManager()->getLanguages() as $language) {
287     // The prefix for this language should be updated if it's not assigned yet
288     // or the prefix is set to the empty string.
289     if (empty($prefixes[$language->getId()])) {
290       // For the default language, set the prefix to the empty string,
291       // otherwise use the langcode.
292       $prefixes[$language->getId()] = $language->isDefault() ? '' : $language->getId();
293     }
294     // Otherwise we keep the configured prefix.
295   }
296   $config->set('url.prefixes', $prefixes)->save();
297 }
298
299 /**
300  * Reads language domains.
301  *
302  * @deprecated in Drupal 8.0.x-dev, will be removed before Drupal 9.0.0.
303  *   Use \Drupal::config('language.negotiation')->get('url.domains') instead.
304  */
305 function language_negotiation_url_domains() {
306   return \Drupal::config('language.negotiation')->get('url.domains');
307 }
308
309 /**
310  * Implements hook_modules_installed().
311  */
312 function language_modules_installed($modules) {
313   if (!in_array('language', $modules)) {
314     // Since newly (un)installed modules may change the default settings for
315     // non-locked language types (e.g. content language), we need to resave the
316     // language type configuration.
317     /** @var \Drupal\language\LanguageNegotiatorInterface $negotiator */
318     $negotiator = \Drupal::service('language_negotiator');
319     $configurable = \Drupal::config('language.types')->get('configurable');
320     $negotiator->updateConfiguration($configurable);
321     $negotiator->purgeConfiguration();
322   }
323   else {
324     // In language_entity_base_field_info_alter() we are altering view/form
325     // display definitions to make language fields display configurable. Since
326     // this is not a hard dependency, and thus is not detected by the config
327     // system, we have to clean up the related values manually.
328     foreach (['entity_view_display', 'entity_form_display'] as $key) {
329       $displays = \Drupal::entityManager()->getStorage($key)->loadMultiple();
330       /** @var \Drupal\Core\Entity\Display\EntityDisplayInterface $display */
331       foreach ($displays as $display) {
332         $display->save();
333       }
334     }
335   }
336 }
337
338 /**
339  * Implements hook_modules_uninstalled().
340  */
341 function language_modules_uninstalled($modules) {
342   language_modules_installed($modules);
343 }
344
345 /**
346  * Implements hook_ENTITY_TYPE_insert() for 'configurable_language'.
347  */
348 function language_configurable_language_insert(ConfigurableLanguageInterface $language) {
349   if ($language->isLocked()) {
350     return;
351   }
352
353   // Add language to the list of language domains.
354   $config = \Drupal::configFactory()->getEditable('language.negotiation');
355   $domains = $config->get('url.domains');
356   $domains[$language->id()] = '';
357   $config->set('url.domains', $domains)->save();
358 }
359
360 /**
361  * Implements hook_ENTITY_TYPE_delete() for 'configurable_language'.
362  */
363 function language_configurable_language_delete(ConfigurableLanguageInterface $language) {
364   // Remove language from language prefix list.
365   $config = \Drupal::configFactory()->getEditable('language.negotiation');
366   $prefixes = $config->get('url.prefixes');
367   unset($prefixes[$language->id()]);
368   $config->set('url.prefixes', $prefixes)->save();
369
370   // Remove language from language domain list.
371   $config = \Drupal::configFactory()->getEditable('language.negotiation');
372   $domains = $config->get('url.domains');
373   unset($domains[$language->id()]);
374   $config->set('url.domains', $domains)->save();
375 }
376
377 /**
378  * Implements hook_preprocess_HOOK() for block templates.
379  */
380 function language_preprocess_block(&$variables) {
381   if ($variables['configuration']['provider'] == 'language') {
382     $variables['attributes']['role'] = 'navigation';
383   }
384 }
385
386 /**
387  * Returns language mappings between browser and Drupal language codes.
388  *
389  * @return array
390  *   An array containing browser language codes as keys with corresponding
391  *   Drupal language codes as values.
392  */
393 function language_get_browser_drupal_langcode_mappings() {
394   $config = \Drupal::config('language.mappings');
395   if ($config->isNew()) {
396     return [];
397   }
398   return $config->get('map');
399 }
400
401 /**
402  * Implements hook_form_alter().
403  */
404 function language_form_alter(&$form, FormStateInterface $form_state) {
405   // Content entity forms may have added a langcode field. But content language
406   // configuration should decide if it should be exposed or not in the forms.
407   $form_object = $form_state->getFormObject();
408   if ($form_object instanceof ContentEntityFormInterface && $form_object->getEntity()->getEntityType()->hasKey('langcode')) {
409     /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
410     $entity = $form_object->getEntity();
411     $entity_type = $entity->getEntityType();
412     $langcode_key = $entity_type->getKey('langcode');
413     if (isset($form[$langcode_key])) {
414       $language_configuration = ContentLanguageSettings::loadByEntityTypeBundle($entity->getEntityTypeId(), $entity->bundle());
415       $form[$langcode_key]['#access'] = $language_configuration->isLanguageAlterable();
416     }
417   }
418 }
419
420 /**
421  * Implements hook_field_info_alter().
422  */
423 function language_field_info_alter(&$info) {
424   // Change the default behavior of language field.
425   $info['language']['class'] = '\Drupal\language\DefaultLanguageItem';
426 }
427
428 /**
429  * Implements hook_entity_field_access()
430  */
431 function language_entity_field_access($operation, FieldDefinitionInterface $field_definition, AccountInterface $account, FieldItemListInterface $items = NULL) {
432   // Only allow edit access on a langcode field if the entity it is attached to
433   // is configured to have an alterable language. Also without items we can not
434   // decide whether or not to allow access.
435   if ($items && $operation == 'edit') {
436     // Check if we are dealing with a langcode field.
437     $langcode_key = $items->getEntity()->getEntityType()->getKey('langcode');
438     if ($field_definition->getName() == $langcode_key) {
439       // Grant access depending on whether the entity language can be altered.
440       $entity = $items->getEntity();
441       $config = ContentLanguageSettings::loadByEntityTypeBundle($entity->getEntityTypeId(), $entity->bundle());
442       return AccessResult::forbiddenIf(!$config->isLanguageAlterable());
443     }
444   }
445   return AccessResult::neutral();
446 }
447
448 /**
449  * Implements hook_tour_tips_alter().
450  */
451 function language_tour_tips_alter(array &$tour_tips, EntityInterface $entity) {
452   foreach ($tour_tips as $tour_tip) {
453     if ($tour_tip->get('id') == 'language-overview') {
454       $additional_overview = '';
455       if (Drupal::service('module_handler')->moduleExists('locale')) {
456         $additional_overview = t("This page also provides an overview of how much of the site's interface has been translated for each configured language.");
457       }
458       else {
459         $additional_overview = t("If the Interface Translation module is enabled, this page will provide an overview of how much of the site's interface has been translated for each configured language.");
460       }
461       $tour_tip->set('body', $tour_tip->get('body') . '<p>' . $additional_overview . '</p>');
462     }
463     elseif ($tour_tip->get('id') == 'language-continue') {
464       $additional_continue = '';
465       $additional_modules = [];
466       if (!Drupal::service('module_handler')->moduleExists('locale')) {
467         $additional_modules[] = Drupal::service('module_handler')->getName('locale');
468       }
469       if (!Drupal::service('module_handler')->moduleExists('content_translation')) {
470         $additional_modules[] = Drupal::service('module_handler')->getName('content_translation');
471       }
472       if (!empty($additional_modules)) {
473         $additional_continue = t('Depending on your site features, additional modules that you might want to enable are:') . '<ul>';
474         foreach ($additional_modules as $additional_module) {
475           $additional_continue .= '<li>' . $additional_module . '</li>';
476         }
477         $additional_continue .= '</ul>';
478       }
479       if (!empty($additional_continue)) {
480         $tour_tip->set('body', $tour_tip->get('body') . '<p>' . $additional_continue . '</p>');
481       }
482     }
483   }
484 }
485
486 /**
487  * Implements hook_language_types_info_alter().
488  *
489  * We can't set the fixed properties in \Drupal\Core\Language\LanguageManager,
490  * where the rest of the properties for the default language types are defined.
491  * The LanguageNegation classes are only loaded when the language module is
492  * enabled and we can't be sure of that in the LanguageManager.
493  */
494 function language_language_types_info_alter(array &$language_types) {
495   $language_types[LanguageInterface::TYPE_CONTENT]['fixed'] = [LanguageNegotiationUI::METHOD_ID];
496   $language_types[LanguageInterface::TYPE_URL]['fixed'] = [LanguageNegotiationUrl::METHOD_ID, LanguageNegotiationUrlFallback::METHOD_ID];
497 }