You are here

class DisableLanguageManager in Disable language 8

Class DisableLanguageManager.

@package Drupal\disable_language

Hierarchy

Expanded class hierarchy of DisableLanguageManager

1 file declares its use of DisableLanguageManager
DisabledLanguagesEventSubscriber.php in src/EventSubscriber/DisabledLanguagesEventSubscriber.php
1 string reference to 'DisableLanguageManager'
disable_language.services.yml in ./disable_language.services.yml
disable_language.services.yml
1 service uses DisableLanguageManager
disable_language.disable_language_manager in ./disable_language.services.yml
Drupal\disable_language\DisableLanguageManager

File

src/DisableLanguageManager.php, line 19

Namespace

Drupal\disable_language
View source
class DisableLanguageManager extends ConfigurableLanguageManager {

  /**
   * Contains entity_type.manager service.
   *
   * @var \Drupal\Core\Entity\EntityTypeManager
   */
  protected $entityTypeManager;

  /**
   * Contains enabled languages.
   *
   * @var enabledLanguages
   */
  protected $enabledLanguages;

  /**
   * Contains disabled languages.
   *
   * @var disabledLanguages
   */
  protected $disabledLanguages;

  /**
   * Contains language_manager service.
   *
   * @var \Drupal\Core\Language\LanguageManager
   */
  protected $languageManager;

  /**
   * DisableLanguageManager constructor.
   *
   * @param \Drupal\Core\Language\LanguageDefault $default_language
   *   Provides a simple get and set wrapper to the default language object.
   * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
   *   Defines the interface for a configuration object factory.
   * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
   *   Interface for classes that manage a set of enabled modules.
   * @param \Drupal\language\Config\LanguageConfigFactoryOverrideInterface $config_override
   *   Interface for a configuration factory language override object.
   * @param \Symfony\Component\HttpFoundation\RequestStack $request_stack
   *   Request stack that controls the lifecycle of requests.
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager
   *   Manages entity type plugin definitions.
   * @param \Drupal\Core\Language\LanguageManager $languageManager
   *   Providing language support on language-unaware sites.
   */
  public function __construct(LanguageDefault $default_language, ConfigFactoryInterface $config_factory, ModuleHandlerInterface $module_handler, LanguageConfigFactoryOverrideInterface $config_override, RequestStack $request_stack, EntityTypeManagerInterface $entityTypeManager, languageManager $languageManager) {
    parent::__construct($default_language, $config_factory, $module_handler, $config_override, $request_stack);
    $this->entityTypeManager = $entityTypeManager;
    $this->languageManager = $languageManager;
    $this->disabledLanguages = [];
    $this->enabledLanguages = [];
  }

  /**
   * {@inheritdoc}
   */
  public function getConfigurableLanguages() {
    $configurableLanguages = [];

    // Get all languages.
    $languages = $this
      ->getLanguages();

    // The language itself doesn't own the thirdPartySetting,
    // So we need to use its matching ConfigEntity
    // Getting the ConfigurableLanguageManager.
    $configManager = $this->entityTypeManager
      ->getStorage('configurable_language');
    $configurableLanguages = $configManager
      ->loadMultiple(array_keys($languages));
    return $configurableLanguages;
  }

  /**
   * {@inheritdoc}
   */
  public function getDisabledLanguages() {
    if (empty($this->disabledLanguages)) {
      foreach ($this
        ->getConfigurableLanguages() as $langcode => $configurableLanguage) {
        $disabled = $configurableLanguage
          ->getThirdPartySetting('disable_language', 'disable');
        if (isset($disabled) && $disabled == 1) {
          $this->disabledLanguages[$langcode] = $configurableLanguage;
        }
      }
    }
    return $this->disabledLanguages;
  }

  /**
   * {@inheritdoc}
   */
  public function getEnabledLanguages() {
    if (empty($this->enabledLanguages)) {
      foreach ($this
        ->getConfigurableLanguages() as $langcode => $configurableLanguage) {
        $disabled = $configurableLanguage
          ->getThirdPartySetting('disable_language', 'disable');
        if (isset($disabled) && $disabled == 0 || empty($disabled)) {
          $this->enabledLanguages[$langcode] = $configurableLanguage;
        }
      }
    }
    return $this->enabledLanguages;
  }

  /**
   * {@inheritdoc}
   */
  public function isCurrentLanguageDisabled() {
    $currentLanguageDisabled = FALSE;
    $disabledLangCodes = array_keys($this
      ->getDisabledLanguages());
    if (isset($disabledLangCodes) && in_array($this->languageManager
      ->getCurrentLanguage()
      ->getId(), $disabledLangCodes)) {
      $currentLanguageDisabled = TRUE;
    }
    return $currentLanguageDisabled;
  }

  /**
   * {@inheritdoc}
   */
  public function getFirstEnabledLanguage() {
    $enabledLanguages = $this
      ->getEnabledLanguages();
    $configurableLanguage = reset($enabledLanguages);
    return $this
      ->getLanguage($configurableLanguage
      ->getId());
  }

  /**
   * Determine and return the fallback language id.
   *
   * @return \Drupal\core\Language\LanguageInterface|null
   *   The id of the language that functions as the fallback.
   */
  public function getFallbackLanguage() {
    $redirect_language = FALSE;
    $disabledLangCodes = array_keys($this
      ->getDisabledLanguages());
    if (isset($disabledLangCodes) && in_array($this->languageManager
      ->getCurrentLanguage()
      ->getId(), $disabledLangCodes)) {

      // Get the configurable languages.
      $lang = $this
        ->getConfigurableLanguages();
      $key = $this->languageManager
        ->getCurrentLanguage()
        ->getId();
      if (array_key_exists($this->languageManager
        ->getCurrentLanguage()
        ->getId(), $lang)) {
        $redirect_language = $lang[$key]
          ->getThirdPartySetting('disable_language', 'redirect_language');
      }
    }
    return $redirect_language;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ConfigurableLanguageManager::$configFactory protected property The configuration storage service.
ConfigurableLanguageManager::$configFactoryOverride protected property The language configuration override service.
ConfigurableLanguageManager::$initialized protected property Whether or not the language manager has been initialized.
ConfigurableLanguageManager::$initializing protected property Whether language types are in the process of language initialization.
ConfigurableLanguageManager::$languageTypes protected property Local cache for language type configuration data.
ConfigurableLanguageManager::$languageTypesInfo protected property Local cache for language type information.
ConfigurableLanguageManager::$moduleHandler protected property The module handler service.
ConfigurableLanguageManager::$negotiatedLanguages protected property An array of language objects keyed by language type.
ConfigurableLanguageManager::$negotiatedMethods protected property An array of language negotiation method IDs keyed by language type.
ConfigurableLanguageManager::$negotiator protected property The language negotiator.
ConfigurableLanguageManager::$requestStack protected property The request object.
ConfigurableLanguageManager::getConfigOverrideLanguage public function Gets the current configuration override language. Overrides LanguageManager::getConfigOverrideLanguage
ConfigurableLanguageManager::getCurrentLanguage public function Returns the current language for the given type. Overrides LanguageManager::getCurrentLanguage
ConfigurableLanguageManager::getDefinedLanguageTypes public function Returns all the defined language types including fixed ones. Overrides ConfigurableLanguageManagerInterface::getDefinedLanguageTypes
ConfigurableLanguageManager::getDefinedLanguageTypesInfo public function Returns information about all defined language types. Overrides LanguageManager::getDefinedLanguageTypesInfo
ConfigurableLanguageManager::getFallbackCandidates public function Returns the language fallback candidates for a given context. Overrides LanguageManager::getFallbackCandidates
ConfigurableLanguageManager::getLanguageConfigOverride public function Gets a language config override object. Overrides ConfigurableLanguageManagerInterface::getLanguageConfigOverride
ConfigurableLanguageManager::getLanguageConfigOverrideStorage public function Gets a language configuration override storage object. Overrides ConfigurableLanguageManagerInterface::getLanguageConfigOverrideStorage
ConfigurableLanguageManager::getLanguages public function Returns a list of languages set up on the site. Overrides LanguageManager::getLanguages
ConfigurableLanguageManager::getLanguageSwitchLinks public function Returns the language switch links for the given language type. Overrides LanguageManager::getLanguageSwitchLinks
ConfigurableLanguageManager::getLanguageTypes public function Returns an array of the available language types. Overrides LanguageManager::getLanguageTypes
ConfigurableLanguageManager::getNativeLanguages public function Returns a list of languages set up on the site in their native form. Overrides LanguageManager::getNativeLanguages
ConfigurableLanguageManager::getNegotiatedLanguageMethod public function Gets the negotiated language method ID. Overrides ConfigurableLanguageManagerInterface::getNegotiatedLanguageMethod
ConfigurableLanguageManager::getNegotiator public function Returns the language negotiator. Overrides ConfigurableLanguageManagerInterface::getNegotiator
ConfigurableLanguageManager::getStandardLanguageListWithoutConfigured public function Returns the standard language list excluding already configured languages. Overrides ConfigurableLanguageManagerInterface::getStandardLanguageListWithoutConfigured
ConfigurableLanguageManager::init public function
ConfigurableLanguageManager::isMultilingual public function Returns whether or not the site has more than one language added. Overrides LanguageManager::isMultilingual
ConfigurableLanguageManager::loadLanguageTypesConfiguration protected function Retrieves language types from the configuration storage.
ConfigurableLanguageManager::rebuildServices public static function Rebuild the container to register services needed on multilingual sites. Overrides ConfigurableLanguageManagerInterface::rebuildServices
ConfigurableLanguageManager::reset public function Resets the given language type or all types if none specified. Overrides LanguageManager::reset
ConfigurableLanguageManager::saveLanguageTypesConfiguration public function Stores language types configuration. Overrides ConfigurableLanguageManagerInterface::saveLanguageTypesConfiguration
ConfigurableLanguageManager::setConfigOverrideLanguage public function Sets the configuration override language. Overrides LanguageManager::setConfigOverrideLanguage
ConfigurableLanguageManager::setNegotiator public function Injects the language negotiator. Overrides ConfigurableLanguageManagerInterface::setNegotiator
ConfigurableLanguageManager::updateLockedLanguageWeights public function Updates locked system language weights. Overrides ConfigurableLanguageManagerInterface::updateLockedLanguageWeights
DependencySerializationTrait::$_entityStorages protected property An array of entity type IDs keyed by the property name of their storages.
DependencySerializationTrait::$_serviceIds protected property An array of service IDs keyed by property name used for serialization.
DependencySerializationTrait::__sleep public function 1
DependencySerializationTrait::__wakeup public function 2
DisableLanguageManager::$disabledLanguages protected property Contains disabled languages.
DisableLanguageManager::$enabledLanguages protected property Contains enabled languages.
DisableLanguageManager::$entityTypeManager protected property Contains entity_type.manager service.
DisableLanguageManager::$languageManager protected property Contains language_manager service.
DisableLanguageManager::getConfigurableLanguages public function
DisableLanguageManager::getDisabledLanguages public function
DisableLanguageManager::getEnabledLanguages public function
DisableLanguageManager::getFallbackLanguage public function Determine and return the fallback language id.
DisableLanguageManager::getFirstEnabledLanguage public function
DisableLanguageManager::isCurrentLanguageDisabled public function
DisableLanguageManager::__construct public function DisableLanguageManager constructor. Overrides ConfigurableLanguageManager::__construct
LanguageManager::$defaultLanguage protected property The default language object.
LanguageManager::$languages protected property A static cache of translated language lists.
LanguageManager::filterLanguages protected function Filters the full list of languages based on the value of the flag.
LanguageManager::getDefaultLanguage public function Returns a language object representing the site's default language. Overrides LanguageManagerInterface::getDefaultLanguage
LanguageManager::getDefaultLockedLanguages public function Returns a list of the default locked languages. Overrides LanguageManagerInterface::getDefaultLockedLanguages
LanguageManager::getLanguage public function Returns a language object from the given language code. Overrides LanguageManagerInterface::getLanguage
LanguageManager::getLanguageName public function Produced the printed name for a language for display. Overrides LanguageManagerInterface::getLanguageName
LanguageManager::getStandardLanguageList public static function Some common languages with their English and native names. Overrides LanguageManagerInterface::getStandardLanguageList
LanguageManager::getUnitedNationsLanguageList public static function The 6 official languages used at the United Nations.
LanguageManager::isLanguageLocked public function Checks whether a language is locked. Overrides LanguageManagerInterface::isLanguageLocked