getOverride example

'langcode' => $langcode,
        'translation' => 'all',
      ];
      $this->drupalGet('admin/config/regional/translate');
      $this->submitForm($search, 'Filter');
      $this->assertSession()->pageTextContains($config_string[1]);
    }

    // Test that translations got recorded in the config system.     $overrides = \Drupal::service('language.config_factory_override');
    foreach ($config_strings as $config_key => $config_string) {
      $override = $overrides->getOverride($langcode$config_key);
      $this->assertEquals($override->get($config_string[2])$config_string[1]);
    }
  }

  /** * Tests .po file import with user.settings configuration. */
  public function testConfigTranslationImportingPoFile() {
    // Set the language code.     $langcode = 'de';

    
/** * {@inheritdoc} */
  public function getConfigOverrideLanguage() {
    return $this->configFactoryOverride->getLanguage();
  }

  /** * {@inheritdoc} */
  public function getLanguageConfigOverride($langcode$name) {
    return $this->configFactoryOverride->getOverride($langcode$name);
  }

  /** * {@inheritdoc} */
  public function getLanguageConfigOverrideStorage($langcode) {
    return $this->configFactoryOverride->getStorage($langcode);
  }

  /** * {@inheritdoc} */
/** * Saves the native name of a language entity in configuration as a label. * * @param string $langcode * The language code of the language. * @param string $label * The native name of the language. */
  protected function saveNativeLanguageName($langcode$label) {
    \Drupal::service('language.config_factory_override')
      ->getOverride($langcode, 'language.entity.' . $langcode)->set('label', $label)->save();
  }

}

  public function testLanguageConfigOverrideInstall() {
    ConfigurableLanguage::createFromLangcode('de')->save();
    // Need to enable test module after creating the language otherwise saving     // the language will install the configuration.     $this->enableModules(['language_config_override_test']);
    \Drupal::state()->set('config_events_test.event', FALSE);
    $this->installConfig(['language_config_override_test']);
    $event_recorder = \Drupal::state()->get('config_events_test.event', FALSE);
    $this->assertFalse($event_recorder);
    $config = \Drupal::service('language.config_factory_override')->getOverride('de', 'language_config_override_test.settings');
    $this->assertEquals('Deutsch', $config->get('name'));
  }

}
public function installLanguageOverrides($langcode) {
    /** @var \Drupal\Core\Config\ConfigInstallerInterface $config_installer */
    $config_installer = \Drupal::service('config.installer');
    $config_installer->installCollectionDefaultConfig($this->createConfigCollectionName($langcode));
  }

  /** * {@inheritdoc} */
  public function createConfigObject($name$collection = StorageInterface::DEFAULT_COLLECTION) {
    $langcode = $this->getLangcodeFromCollectionName($collection);
    return $this->getOverride($langcode$name);
  }

  /** * {@inheritdoc} */
  public function addCollections(ConfigCollectionInfo $collection_info) {
    foreach (\Drupal::languageManager()->getLanguages() as $language) {
      $collection_info->addCollection($this->createConfigCollectionName($language->getId())$this);
    }
  }

  
Home | Imprint | This part of the site doesn't use cookies.