public static function LimitLanguageOptionsCallback::preRender in Language access 8
Alters the language widget options. This method is used in #pre_render.
Limits the options to those that the user is allowed to access.
Parameters
array $element: The language form element.
Return value
array The language form element.
File
- src/
LimitLanguageOptionsCallback.php, line 31
Class
- LimitLanguageOptionsCallback
- Class that contains callbacks to alter language elements.
Namespace
Drupal\language_accessCode
public static function preRender(array $element) : array {
$languages = \Drupal::languageManager()
->getLanguages();
foreach (array_keys($element['#options']) as $id) {
if (isset($languages[$id]) && !$element['#for_user']
->hasPermission('access language ' . $id)) {
unset($element['#options'][$id]);
}
}
unset($element['#for_user']);
return $element;
}