You are here

protected function ConfigFormBaseTrait::config in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/lib/Drupal/Core/Form/ConfigFormBaseTrait.php \Drupal\Core\Form\ConfigFormBaseTrait::config()

Retrieves a configuration object.

Objects that use the trait need to implement the \Drupal\Core\Form\ConfigFormBaseTrait::getEditableConfigNames() to declare which configuration objects this method returns override free and mutable. This ensures that overrides do not pollute saved configuration.

Parameters

string $name: The name of the configuration object to retrieve. The name corresponds to a configuration file. For

\Drupal::config('book.admin');

, the config object returned will contain the contents of book.admin configuration file.

Return value

\Drupal\Core\Config\Config|\Drupal\Core\Config\ImmutableConfig A configuration object.

34 calls to ConfigFormBaseTrait::config()
AccountSettingsForm::buildForm in core/modules/user/src/AccountSettingsForm.php
Form constructor.
AdvancedSettingsForm::buildForm in core/modules/views_ui/src/Form/AdvancedSettingsForm.php
Form constructor.
BasicSettingsForm::buildForm in core/modules/views_ui/src/Form/BasicSettingsForm.php
Form constructor.
BookSettingsForm::buildForm in core/modules/book/src/Form/BookSettingsForm.php
Form constructor.
ContactFormEditForm::save in core/modules/contact/src/ContactFormEditForm.php
Form submission handler for the 'save' action.

... See full list

File

core/lib/Drupal/Core/Form/ConfigFormBaseTrait.php, line 47
Contains \Drupal\Core\Form\ConfigFormBaseTrait.

Class

ConfigFormBaseTrait
Provides access to configuration for forms.

Namespace

Drupal\Core\Form

Code

protected function config($name) {

  /** @var \Drupal\Core\Config\ConfigFactoryInterface $config_factory */
  if (method_exists($this, 'configFactory')) {
    $config_factory = $this
      ->configFactory();
  }
  elseif (property_exists($this, 'configFactory')) {
    $config_factory = $this->configFactory;
  }
  if (!isset($config_factory) || !$config_factory instanceof ConfigFactoryInterface) {
    throw new \LogicException('No config factory available for ConfigFormBaseTrait');
  }
  if (in_array($name, $this
    ->getEditableConfigNames())) {

    // Get a mutable object from the factory.
    $config = $config_factory
      ->getEditable($name);
  }
  else {
    $config = $config_factory
      ->get($name);
  }
  return $config;
}