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

Retrieves a configuration object.

Parameters

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

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

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

Return value

\Drupal\Core\Config\Config|\Drupal\Core\Config\ImmutableConfig An editable configuration object if the given name is listed in the getEditableConfigNames() method or an immutable configuration object if not.

7 calls to ConfigFormBaseTrait::config()
ContactFormEditForm::form in core/modules/contact/src/ContactFormEditForm.php
Gets the actual form array to be built.
ContactFormEditForm::save in core/modules/contact/src/ContactFormEditForm.php
Form submission handler for the 'save' action.
CronForm::buildForm in core/modules/system/src/Form/CronForm.php
Form constructor.
CronForm::submitForm in core/modules/system/src/Form/CronForm.php
Form submission handler.
NegotiationBrowserDeleteForm::submitForm in core/modules/language/src/Form/NegotiationBrowserDeleteForm.php
Form submission handler.

... See full list

File

core/lib/Drupal/Core/Form/ConfigFormBaseTrait.php, line 39

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;
}