language.module 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468
  1. <?php
  2. /**
  3. * @file
  4. * Add language handling functionality to Drupal.
  5. */
  6. use Drupal\Core\Access\AccessResult;
  7. use Drupal\Core\Entity\ContentEntityFormInterface;
  8. use Drupal\Core\Entity\EntityFormInterface;
  9. use Drupal\Core\Entity\EntityInterface;
  10. use Drupal\Core\Field\FieldDefinitionInterface;
  11. use Drupal\Core\Field\FieldItemListInterface;
  12. use Drupal\Core\Form\FormStateInterface;
  13. use Drupal\Core\Language\LanguageInterface;
  14. use Drupal\Core\Routing\RouteMatchInterface;
  15. use Drupal\Core\Session\AccountInterface;
  16. use Drupal\language\Entity\ContentLanguageSettings;
  17. use Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationUI;
  18. use Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationUrl;
  19. use Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationUrlFallback;
  20. /**
  21. * Implements hook_help().
  22. */
  23. function language_help($route_name, RouteMatchInterface $route_match) {
  24. switch ($route_name) {
  25. case 'help.page.language':
  26. $output = '';
  27. $output .= '<h3>' . t('About') . '</h3>';
  28. $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>';
  29. $output .= '<h3>' . t('Uses') . '</h3>';
  30. $output .= '<dl>';
  31. $output .= '<dt>' . t('Adding languages') . '</dt>';
  32. $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>';
  33. $output .= '<dt>' . t('Adding custom languages') . '</dt>';
  34. $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>';
  35. $output .= '<dt>' . t('Configuring content languages') . '</dt>';
  36. $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>';
  37. $output .= '<dt>' . t('Adding a language switcher block') . '</dt>';
  38. $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>';
  39. $output .= '<dt>' . t('Making a block visible per language') . '</dt>';
  40. $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>';
  41. $output .= '<dt>' . t('Choosing user languages') . '</dt>';
  42. $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>';
  43. $output .= '<dt>' . t('Language detection and selection') . '</dt>';
  44. $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')]);
  45. $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>';
  46. $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>';
  47. $output .= '<li>' . t("<em>User</em> follows the language configuration set on the user's profile page.") . '</li>';
  48. $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>';
  49. $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>';
  50. $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>';
  51. $output .= '</dl>';
  52. return $output;
  53. case 'entity.configurable_language.collection':
  54. $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>';
  55. $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>';
  56. return $output;
  57. case 'language.add':
  58. 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>';
  59. case 'language.negotiation':
  60. $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>';
  61. return $output;
  62. case 'language.negotiation_session':
  63. $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>';
  64. return $output;
  65. case 'language.negotiation_browser':
  66. $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>';
  67. return $output;
  68. case 'language.negotiation_selected':
  69. $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>';
  70. return $output;
  71. case 'entity.block.edit_form':
  72. if (($block = $route_match->getParameter('block')) && $block->getPluginId() == 'language_block:language_interface') {
  73. return '<p>' . t('With multiple languages configured, registered users can select their preferred language and authors can assign a specific language to content.') . '</p>';
  74. }
  75. break;
  76. case 'block.admin_add':
  77. if ($route_match->getParameter('plugin_id') == 'language_block:language_interface') {
  78. return '<p>' . t('With multiple languages configured, registered users can select their preferred language and authors can assign a specific language to content.') . '</p>';
  79. }
  80. break;
  81. case 'language.content_settings_page':
  82. 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>';
  83. }
  84. }
  85. /**
  86. * Implements hook_theme().
  87. */
  88. function language_theme() {
  89. return [
  90. 'language_negotiation_configure_form' => [
  91. 'render element' => 'form',
  92. 'file' => 'language.admin.inc',
  93. ],
  94. 'language_content_settings_table' => [
  95. 'render element' => 'element',
  96. 'file' => 'language.admin.inc',
  97. ],
  98. ];
  99. }
  100. /**
  101. * Implements hook_element_info_alter().
  102. *
  103. * @see \Drupal\Core\Render\Element\LanguageSelect
  104. * @see \Drupal\Core\Render\Element\Select
  105. */
  106. function language_element_info_alter(&$type) {
  107. // Alter the language_select element so that it will be rendered like a select
  108. // field.
  109. if (isset($type['language_select'])) {
  110. if (!isset($type['language_select']['#process'])) {
  111. $type['language_select']['#process'] = [];
  112. }
  113. if (!isset($type['language_select']['#theme_wrappers'])) {
  114. $type['language_select']['#theme_wrappers'] = [];
  115. }
  116. $type['language_select']['#process'] = array_merge($type['language_select']['#process'], [
  117. 'language_process_language_select',
  118. ['Drupal\Core\Render\Element\Select', 'processSelect'],
  119. ['Drupal\Core\Render\Element\RenderElement', 'processAjaxForm'],
  120. ]);
  121. $type['language_select']['#theme'] = 'select';
  122. $type['language_select']['#theme_wrappers'] = array_merge($type['language_select']['#theme_wrappers'], ['form_element']);
  123. $type['language_select']['#languages'] = LanguageInterface::STATE_CONFIGURABLE;
  124. $type['language_select']['#multiple'] = FALSE;
  125. }
  126. }
  127. /**
  128. * Processes a language select list form element.
  129. *
  130. * @param array $element
  131. * The form element to process.
  132. *
  133. * @return array
  134. * The processed form element.
  135. */
  136. function language_process_language_select($element) {
  137. // Don't set the options if another module (translation for example) already
  138. // set the options.
  139. if (!isset($element['#options'])) {
  140. $element['#options'] = [];
  141. foreach (\Drupal::languageManager()->getLanguages($element['#languages']) as $langcode => $language) {
  142. $element['#options'][$langcode] = $language->isLocked() ? t('- @name -', ['@name' => $language->getName()]) : $language->getName();
  143. }
  144. }
  145. return $element;
  146. }
  147. /**
  148. * Implements hook_entity_base_field_info_alter().
  149. */
  150. function language_entity_base_field_info_alter(&$fields) {
  151. foreach ($fields as $definition) {
  152. // Set configurable form display for language fields with display options.
  153. if ($definition->getType() == 'language') {
  154. foreach (['form', 'view'] as $type) {
  155. if ($definition->getDisplayOptions($type)) {
  156. // The related configurations will be purged manually on Language
  157. // module uninstallation. @see language_modules_uninstalled().
  158. $definition->setDisplayConfigurable($type, TRUE);
  159. }
  160. }
  161. }
  162. }
  163. }
  164. /**
  165. * Submit handler for the forms that have a language_configuration element.
  166. */
  167. function language_configuration_element_submit(&$form, FormStateInterface $form_state) {
  168. // Iterate through all the language_configuration elements and save their
  169. // values.
  170. // In case we are editing a bundle, we must check the new bundle name,
  171. // because e.g. hook_ENTITY_update fired before.
  172. if ($language = $form_state->get('language')) {
  173. foreach ($language as $element_name => $values) {
  174. $entity_type_id = $values['entity_type'];
  175. $bundle = $values['bundle'];
  176. $form_object = $form_state->getFormObject();
  177. if ($form_object instanceof EntityFormInterface) {
  178. /** @var \Drupal\Core\Entity\EntityFormInterface $form_object */
  179. $entity = $form_object->getEntity();
  180. if ($entity->getEntityType()->getBundleOf()) {
  181. $bundle = $entity->id();
  182. $language[$element_name]['bundle'] = $bundle;
  183. }
  184. }
  185. $config = ContentLanguageSettings::loadByEntityTypeBundle($entity_type_id, $bundle);
  186. $config->setDefaultLangcode($form_state->getValue([$element_name, 'langcode']));
  187. $config->setLanguageAlterable($form_state->getValue([$element_name, 'language_alterable']));
  188. $config->save();
  189. // Set the form_state language with the updated bundle.
  190. $form_state->set('language', $language);
  191. }
  192. }
  193. }
  194. /**
  195. * Implements hook_entity_bundle_delete().
  196. */
  197. function language_entity_bundle_delete($entity_type_id, $bundle) {
  198. // Remove the content language settings associated with the bundle.
  199. $settings = ContentLanguageSettings::loadByEntityTypeBundle($entity_type_id, $bundle);
  200. if (!$settings->isNew()) {
  201. $settings->delete();
  202. }
  203. }
  204. /**
  205. * Returns the default language code assigned to an entity type and a bundle.
  206. *
  207. * @param string $entity_type
  208. * The entity type.
  209. * @param string $bundle
  210. * The bundle name.
  211. *
  212. * @return string
  213. * The language code.
  214. */
  215. function language_get_default_langcode($entity_type, $bundle) {
  216. $configuration = ContentLanguageSettings::loadByEntityTypeBundle($entity_type, $bundle);
  217. $default_value = NULL;
  218. $language_interface = \Drupal::languageManager()->getCurrentLanguage();
  219. switch ($configuration->getDefaultLangcode()) {
  220. case LanguageInterface::LANGCODE_SITE_DEFAULT:
  221. $default_value = \Drupal::languageManager()->getDefaultLanguage()->getId();
  222. break;
  223. case 'current_interface':
  224. $default_value = $language_interface->getId();
  225. break;
  226. case 'authors_default':
  227. $user = \Drupal::currentUser();
  228. $language_code = $user->getPreferredLangcode();
  229. if (!empty($language_code)) {
  230. $default_value = $language_code;
  231. }
  232. else {
  233. $default_value = $language_interface->getId();
  234. }
  235. break;
  236. }
  237. if ($default_value) {
  238. return $default_value;
  239. }
  240. // If we still do not have a default value, just return the value stored in
  241. // the configuration; it has to be an actual language code.
  242. return $configuration->getDefaultLangcode();
  243. }
  244. /**
  245. * Reads language prefixes and uses the langcode if no prefix is set.
  246. *
  247. * @deprecated in Drupal 8.0.x-dev, will be removed before Drupal 9.0.0.
  248. * Use \Drupal::config('language.negotiation')->get('url.prefixes') instead.
  249. *
  250. * @see https://www.drupal.org/node/2912748
  251. */
  252. function language_negotiation_url_prefixes() {
  253. return \Drupal::config('language.negotiation')->get('url.prefixes');
  254. }
  255. /**
  256. * Update the list of prefixes from the installed languages.
  257. */
  258. function language_negotiation_url_prefixes_update() {
  259. $config = \Drupal::configFactory()->getEditable('language.negotiation');
  260. $prefixes = $config->get('url.prefixes');
  261. foreach (\Drupal::languageManager()->getLanguages() as $language) {
  262. // The prefix for this language should be updated if it's not assigned yet
  263. // or the prefix is set to the empty string.
  264. if (empty($prefixes[$language->getId()])) {
  265. // For the default language, set the prefix to the empty string,
  266. // otherwise use the langcode.
  267. $prefixes[$language->getId()] = $language->isDefault() ? '' : $language->getId();
  268. }
  269. // Otherwise we keep the configured prefix.
  270. }
  271. $config->set('url.prefixes', $prefixes)->save();
  272. }
  273. /**
  274. * Reads language domains.
  275. *
  276. * @deprecated in Drupal 8.0.x-dev, will be removed before Drupal 9.0.0.
  277. * Use \Drupal::config('language.negotiation')->get('url.domains') instead.
  278. *
  279. * @see https://www.drupal.org/node/2912748
  280. */
  281. function language_negotiation_url_domains() {
  282. return \Drupal::config('language.negotiation')->get('url.domains');
  283. }
  284. /**
  285. * Implements hook_modules_installed().
  286. */
  287. function language_modules_installed($modules) {
  288. if (!in_array('language', $modules)) {
  289. // Since newly (un)installed modules may change the default settings for
  290. // non-locked language types (e.g. content language), we need to resave the
  291. // language type configuration.
  292. /** @var \Drupal\language\LanguageNegotiatorInterface $negotiator */
  293. $negotiator = \Drupal::service('language_negotiator');
  294. $configurable = \Drupal::config('language.types')->get('configurable');
  295. $negotiator->updateConfiguration($configurable);
  296. $negotiator->purgeConfiguration();
  297. }
  298. else {
  299. // In language_entity_base_field_info_alter() we are altering view/form
  300. // display definitions to make language fields display configurable. Since
  301. // this is not a hard dependency, and thus is not detected by the config
  302. // system, we have to clean up the related values manually.
  303. foreach (['entity_view_display', 'entity_form_display'] as $key) {
  304. $displays = \Drupal::entityManager()->getStorage($key)->loadMultiple();
  305. /** @var \Drupal\Core\Entity\Display\EntityDisplayInterface $display */
  306. foreach ($displays as $display) {
  307. $display->save();
  308. }
  309. }
  310. }
  311. }
  312. /**
  313. * Implements hook_modules_uninstalled().
  314. */
  315. function language_modules_uninstalled($modules) {
  316. language_modules_installed($modules);
  317. }
  318. /**
  319. * Implements hook_preprocess_HOOK() for block templates.
  320. */
  321. function language_preprocess_block(&$variables) {
  322. if ($variables['configuration']['provider'] == 'language') {
  323. $variables['attributes']['role'] = 'navigation';
  324. }
  325. }
  326. /**
  327. * Returns language mappings between browser and Drupal language codes.
  328. *
  329. * @return array
  330. * An array containing browser language codes as keys with corresponding
  331. * Drupal language codes as values.
  332. */
  333. function language_get_browser_drupal_langcode_mappings() {
  334. $config = \Drupal::config('language.mappings');
  335. if ($config->isNew()) {
  336. return [];
  337. }
  338. return $config->get('map');
  339. }
  340. /**
  341. * Implements hook_form_alter().
  342. */
  343. function language_form_alter(&$form, FormStateInterface $form_state) {
  344. // Content entity forms may have added a langcode field. But content language
  345. // configuration should decide if it should be exposed or not in the forms.
  346. $form_object = $form_state->getFormObject();
  347. if ($form_object instanceof ContentEntityFormInterface && $form_object->getEntity()->getEntityType()->hasKey('langcode')) {
  348. /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
  349. $entity = $form_object->getEntity();
  350. $entity_type = $entity->getEntityType();
  351. $langcode_key = $entity_type->getKey('langcode');
  352. if (isset($form[$langcode_key])) {
  353. $language_configuration = ContentLanguageSettings::loadByEntityTypeBundle($entity->getEntityTypeId(), $entity->bundle());
  354. $form[$langcode_key]['#access'] = $language_configuration->isLanguageAlterable();
  355. }
  356. }
  357. }
  358. /**
  359. * Implements hook_field_info_alter().
  360. */
  361. function language_field_info_alter(&$info) {
  362. // Change the default behavior of language field.
  363. $info['language']['class'] = '\Drupal\language\DefaultLanguageItem';
  364. }
  365. /**
  366. * Implements hook_entity_field_access()
  367. */
  368. function language_entity_field_access($operation, FieldDefinitionInterface $field_definition, AccountInterface $account, FieldItemListInterface $items = NULL) {
  369. // Only allow edit access on a langcode field if the entity it is attached to
  370. // is configured to have an alterable language. Also without items we can not
  371. // decide whether or not to allow access.
  372. if ($items && $operation == 'edit') {
  373. // Check if we are dealing with a langcode field.
  374. $langcode_key = $items->getEntity()->getEntityType()->getKey('langcode');
  375. if ($field_definition->getName() == $langcode_key) {
  376. // Grant access depending on whether the entity language can be altered.
  377. $entity = $items->getEntity();
  378. $config = ContentLanguageSettings::loadByEntityTypeBundle($entity->getEntityTypeId(), $entity->bundle());
  379. return AccessResult::forbiddenIf(!$config->isLanguageAlterable());
  380. }
  381. }
  382. return AccessResult::neutral();
  383. }
  384. /**
  385. * Implements hook_tour_tips_alter().
  386. */
  387. function language_tour_tips_alter(array &$tour_tips, EntityInterface $entity) {
  388. foreach ($tour_tips as $tour_tip) {
  389. if ($tour_tip->get('id') == 'language-overview') {
  390. $additional_overview = '';
  391. if (Drupal::service('module_handler')->moduleExists('locale')) {
  392. $additional_overview = t("This page also provides an overview of how much of the site's interface has been translated for each configured language.");
  393. }
  394. else {
  395. $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.");
  396. }
  397. $tour_tip->set('body', $tour_tip->get('body') . '<p>' . $additional_overview . '</p>');
  398. }
  399. elseif ($tour_tip->get('id') == 'language-continue') {
  400. $additional_continue = '';
  401. $additional_modules = [];
  402. if (!Drupal::service('module_handler')->moduleExists('locale')) {
  403. $additional_modules[] = Drupal::service('module_handler')->getName('locale');
  404. }
  405. if (!Drupal::service('module_handler')->moduleExists('content_translation')) {
  406. $additional_modules[] = Drupal::service('module_handler')->getName('content_translation');
  407. }
  408. if (!empty($additional_modules)) {
  409. $additional_continue = t('Depending on your site features, additional modules that you might want to enable are:') . '<ul>';
  410. foreach ($additional_modules as $additional_module) {
  411. $additional_continue .= '<li>' . $additional_module . '</li>';
  412. }
  413. $additional_continue .= '</ul>';
  414. }
  415. if (!empty($additional_continue)) {
  416. $tour_tip->set('body', $tour_tip->get('body') . '<p>' . $additional_continue . '</p>');
  417. }
  418. }
  419. }
  420. }
  421. /**
  422. * Implements hook_language_types_info_alter().
  423. *
  424. * We can't set the fixed properties in \Drupal\Core\Language\LanguageManager,
  425. * where the rest of the properties for the default language types are defined.
  426. * The LanguageNegation classes are only loaded when the language module is
  427. * enabled and we can't be sure of that in the LanguageManager.
  428. */
  429. function language_language_types_info_alter(array &$language_types) {
  430. $language_types[LanguageInterface::TYPE_CONTENT]['fixed'] = [LanguageNegotiationUI::METHOD_ID];
  431. $language_types[LanguageInterface::TYPE_URL]['fixed'] = [LanguageNegotiationUrl::METHOD_ID, LanguageNegotiationUrlFallback::METHOD_ID];
  432. }