trait ConfigFormBaseTrait (View source)

Provides access to configuration for forms.

This trait provides a config() method that returns override free and mutable config objects if the configuration name is in the array returned by the getEditableConfigNames() implementation.

Forms that present configuration to the user have to take care not to save configuration overrides to the stored configuration since overrides are often environment specific. Default values of form elements should be obtained from override free configuration objects. However, if a form reacts to configuration in any way, for example sends an email to the system.site:mail address, then it is important that the value comes from a configuration object with overrides. Therefore, override free and editable configuration objects are limited to those listed by the getEditableConfigNames() method.

Methods

config(string $name)

Retrieves a configuration object.

array
getEditableConfigNames()

Gets the configuration names that will be editable.

Details

protected Config|ImmutableConfig config(string $name)

Retrieves a configuration object.

Parameters

string $name

The name of the configuration object to retrieve. The name corresponds to a configuration file. For @code \Drupal::config('book.admin') @endcode, the config object returned will contain the contents of book.admin configuration file.

Return Value

Config|ImmutableConfig

An editable configuration object if the given name is listed in the getEditableConfigNames() method or an immutable configuration object if not.

abstract protected array getEditableConfigNames()

Gets the configuration names that will be editable.

Return Value

array

An array of configuration object names that are editable if called in conjunction with the trait's config() method.