You are here

public function LanguageHierarchyConfigFactoryOverride::getOverride in Language Hierarchy 8

Same name and namespace in other branches
  1. 2.x src/Config/LanguageHierarchyConfigFactoryOverride.php \Drupal\language_hierarchy\Config\LanguageHierarchyConfigFactoryOverride::getOverride()

Get language override for given language and configuration name.

Parameters

string $langcode: Language code.

string $name: Configuration name.

Return value

\Drupal\Core\Config\Config Configuration override object.

Overrides LanguageConfigFactoryOverride::getOverride

File

src/Config/LanguageHierarchyConfigFactoryOverride.php, line 56

Class

LanguageHierarchyConfigFactoryOverride
Provides language overrides for the configuration factory, with fallbacks.

Namespace

Drupal\language_hierarchy\Config

Code

public function getOverride($langcode, $name) {
  $source_storage = $target_storage = $this
    ->getStorage($langcode);
  $data = $source_storage
    ->read($name);
  if (empty($data)) {

    // Try fallback languages.
    if ($ancestors = $this
      ->getFallbackChainFromConfigEntities($langcode)) {
      while (empty($data) && ($ancestor = array_shift($ancestors))) {
        $fallback_storage = $this
          ->getStorage($ancestor);
        if ($data = $fallback_storage
          ->read($name)) {
          $source_storage = $fallback_storage;
        }
      }
      $override = new LanguageHierarchyConfigOverride($name, $langcode, $source_storage, $target_storage, $this->typedConfigManager, $this->eventDispatcher);
      if (!empty($data)) {
        $override
          ->initWithData($data);
      }
      return $override;
    }
  }

  // If there is data for the specified language, or there are no fallbacks,
  // use the original implementation of ::getOverride().
  return parent::getOverride($langcode, $name);
}