class AllowedLanguagesTrustedCallbacks in Allowed Languages 2.x
Trusted callbacks for allowed languages form alters.
Hierarchy
- class \Drupal\allowed_languages\Form\AllowedLanguagesTrustedCallbacks implements TrustedCallbackInterface
Expanded class hierarchy of AllowedLanguagesTrustedCallbacks
1 file declares its use of AllowedLanguagesTrustedCallbacks
File
- src/
Form/ AllowedLanguagesTrustedCallbacks.php, line 11
Namespace
Drupal\allowed_languages\FormView source
class AllowedLanguagesTrustedCallbacks implements TrustedCallbackInterface {
/**
* {@inheritdoc}
*/
public static function trustedCallbacks() {
return [
'languageSelectWidgetPreRender',
];
}
/**
* Removes any languages that the user is not allowed to create content for.
*/
public static function languageSelectWidgetPreRender($build) {
$allowed_languages = \Drupal::service('allowed_languages.allowed_languages_manager')
->assignedLanguages();
// Remove any languages that the user is not allowed to add content for.
foreach ($build['value']['#options'] as $language_code => $language_option) {
// If the language is allowed then continue.
if (in_array($language_code, $allowed_languages)) {
continue;
}
// Always allow the not specified and not applicable language options.
if ($language_code === LanguageInterface::LANGCODE_NOT_SPECIFIED || $language_code === LanguageInterface::LANGCODE_NOT_APPLICABLE) {
continue;
}
unset($build['value']['#options'][$language_code]);
}
return $build;
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AllowedLanguagesTrustedCallbacks:: |
public static | function | Removes any languages that the user is not allowed to create content for. | |
AllowedLanguagesTrustedCallbacks:: |
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. |