hidden_language.module in Hidden Language 8
File
hidden_language.module
View source
<?php
use Drupal\Core\Form\FormStateInterface;
use Drupal\language\ConfigurableLanguageInterface;
use Drupal\language\Entity\ConfigurableLanguage;
function hidden_language_form_language_admin_overview_form_alter(&$form, FormStateInterface $form_state) {
$languages = $form['languages']['#languages'];
array_splice($form['languages']['#header'], -1, 0, [
'hidden' => t('Hidden'),
]);
foreach ($languages as $langcode => $language) {
$form['languages'][$langcode]['hidden'] = array(
'#type' => 'checkbox',
'#title' => t('Hidden'),
'#title_display' => 'invisible',
'#default_value' => $language
->getThirdPartySetting('hidden_language', 'hidden', FALSE),
);
}
$form['#submit'][] = 'hidden_language_language_admin_overview_form_submit';
}
function hidden_language_language_admin_overview_form_submit($form, FormStateInterface $form_state) {
$languages = $form['languages']['#languages'];
$language_form_values = $form_state
->getValue('languages');
foreach ($languages as $language) {
if (isset($language_form_values[$language
->id()])) {
$language_form_value = $language_form_values[$language
->id()];
$language
->setThirdPartySetting('hidden_language', 'hidden', boolval($language_form_value['hidden']));
$language
->save();
}
}
}
function hidden_language_language_switch_links_alter(array &$links, $type, $path) {
$languages = \Drupal::languageManager()
->getLanguages();
$languages = ConfigurableLanguage::loadMultiple(array_keys($languages));
foreach ($languages as $langcode => $language) {
if ($language
->getThirdPartySetting('hidden_language', 'hidden', FALSE)) {
unset($links[$langcode]);
}
}
}