class DisableLanguageCallback in Disable language 8
Hierarchy
- class \Drupal\disable_language\DisableLanguageCallback implements TrustedCallbackInterface
Expanded class hierarchy of DisableLanguageCallback
File
- src/
DisableLanguageCallback.php, line 7
Namespace
Drupal\disable_languageView source
class DisableLanguageCallback implements TrustedCallbackInterface {
public static function trustedCallbacks() {
return [
'preRender',
];
}
public static function preRender($element) {
if (\Drupal::currentUser()
->hasPermission('view disabled languages')) {
return $element;
}
$enabled_languages = \Drupal::service('disable_language.disable_language_manager')
->getEnabledLanguages();
$enabled_langcodes = array_keys($enabled_languages);
$langcode_options = array_keys($element['#options']);
// Only keep the enabled languages.
foreach (array_diff($langcode_options, $enabled_langcodes) as $langcode) {
unset($element['#options'][$langcode]);
}
return $element;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DisableLanguageCallback:: |
public static | function | ||
DisableLanguageCallback:: |
public static | function |
Lists the trusted callbacks provided by the implementing class. Overrides TrustedCallbackInterface:: |
|
TrustedCallbackInterface:: |
constant | Untrusted callbacks throw exceptions. | ||
TrustedCallbackInterface:: |
constant | Untrusted callbacks trigger silenced E_USER_DEPRECATION errors. | ||
TrustedCallbackInterface:: |
constant | Untrusted callbacks trigger E_USER_WARNING errors. |