language_selection_page.install in Language Selection Page 8.2
File
language_selection_page.install
View source
<?php
declare (strict_types=1);
use Drupal\Core\Url;
use Drupal\language_selection_page\Plugin\LanguageNegotiation\LanguageNegotiationLanguageSelectionPage;
function language_selection_page_requirements($phase) {
$requirements = [];
if ($phase === 'install') {
return $requirements;
}
$languages = \Drupal::languageManager()
->getNativeLanguages();
$language_negotiation_config = \Drupal::config('language.negotiation')
->get('url');
$prefixes = array_filter($language_negotiation_config['prefixes']);
$lang_list_without_prefix = [];
foreach ($languages as $language) {
if (empty($prefixes[$language
->getId()])) {
$lang_list_without_prefix[$language
->getId()] = t('You should <a href=":admin">add a path prefix</a> to @language language if you want to have it enabled in the Language Selection Page.', [
'@language' => $language
->getName(),
':admin' => Url::fromRoute('language.negotiation_url')
->toString(),
]);
}
}
if (count($lang_list_without_prefix) >= 1) {
$requirements['language_selection_page'] = [
'title' => 'Language Selection Page',
'value' => [
'#theme' => 'item_list',
'#items' => $lang_list_without_prefix,
],
];
}
else {
$requirements['language_selection_page'] = [
'title' => 'Language Selection Page',
'value' => t('All your languages have language prefixes.'),
'severity' => REQUIREMENT_OK,
];
}
return $requirements;
}
function language_selection_page_uninstall() {
$config = \Drupal::configFactory()
->getEditable('language.types');
$language_types = \Drupal::languageManager()
->getLanguageTypes();
foreach ($language_types as $type) {
$config
->clear('negotiation.' . $type . '.enabled.' . LanguageNegotiationLanguageSelectionPage::METHOD_ID);
}
$config
->save();
}