You are here

class DisableLanguageCallback in Disable language 8

Hierarchy

Expanded class hierarchy of DisableLanguageCallback

File

src/DisableLanguageCallback.php, line 7

Namespace

Drupal\disable_language
View 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

Namesort descending Modifiers Type Description Overrides
DisableLanguageCallback::preRender public static function
DisableLanguageCallback::trustedCallbacks public static function Lists the trusted callbacks provided by the implementing class. Overrides TrustedCallbackInterface::trustedCallbacks
TrustedCallbackInterface::THROW_EXCEPTION constant Untrusted callbacks throw exceptions.
TrustedCallbackInterface::TRIGGER_SILENCED_DEPRECATION constant Untrusted callbacks trigger silenced E_USER_DEPRECATION errors.
TrustedCallbackInterface::TRIGGER_WARNING constant Untrusted callbacks trigger E_USER_WARNING errors.