setConfigFactory example


abstract class ConfigFormBase extends FormBase {
  use ConfigFormBaseTrait;

  /** * Constructs a \Drupal\system\ConfigFormBase object. * * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory * The factory for configuration objects. */
  public function __construct(ConfigFactoryInterface $config_factory) {
    $this->setConfigFactory($config_factory);
  }

  /** * {@inheritdoc} */
  public static function create(ContainerInterface $container) {
    return new static(
      $container->get('config.factory')
    );
  }

  


  /** * Tests ConfigNamesMapper::getLangcode(). */
  public function testGetLangcode() {
    // Test that the getLangcode() falls back to 'en', if no explicit language     // code is provided.     $config_factory = $this->getConfigFactoryStub([
      'system.site' => ['key' => 'value'],
    ]);
    $this->configNamesMapper->setConfigFactory($config_factory);
    $result = $this->configNamesMapper->getLangcode();
    $this->assertSame('en', $result);

    // Test that getLangcode picks up the language code provided by the     // configuration.     $config_factory = $this->getConfigFactoryStub([
      'system.site' => ['langcode' => 'xx'],
    ]);
    $this->configNamesMapper->setConfigFactory($config_factory);
    $result = $this->configNamesMapper->getLangcode();
    $this->assertSame('xx', $result);

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