class ImmutableConfig extends Config (View source)

Defines the immutable configuration object.

Encapsulates all capabilities needed for runtime configuration handling except being able to change the configuration.

If you need to be able to change configuration use \Drupal\Core\Form\ConfigFormBaseTrait or \Drupal\Core\Config\ConfigFactoryInterface::getEditable().

Traits

Provides dependency injection friendly methods for serialization.

Trait for \Drupal\Core\Cache\RefinableCacheableDependencyInterface.

Trait for \Drupal\Core\Cache\CacheableDependencyInterface.

Constants

MAX_NAME_LENGTH

The maximum length of a configuration object name.

Many filesystems (including HFS, NTFS, and ext4) have a maximum file name length of 255 characters. To ensure that no configuration objects incompatible with this limitation are created, we enforce a maximum name length of 250 characters (leaving 5 characters for the file extension).

Properties

protected array $_serviceIds

An array of service IDs keyed by property name used for serialization.

from  DependencySerializationTrait
protected array $_entityStorages

An array of entity type IDs keyed by the property name of their storages.

from  DependencySerializationTrait
protected string[] $cacheContexts

Cache contexts.

from  CacheableDependencyTrait
protected string[] $cacheTags

Cache tags.

from  CacheableDependencyTrait
protected int $cacheMaxAge

Cache max-age.

from  CacheableDependencyTrait
protected string $name

The name of the configuration object.

from  ConfigBase
protected array $data

The data of the configuration object.

from  ConfigBase
protected StorageInterface $storage

The storage used to load and save this configuration object.

from  StorableConfigBase
protected Element $schemaWrapper

The config schema wrapper object for this configuration object.

from  StorableConfigBase
protected TypedConfigManagerInterface $typedConfigManager

The typed config manager.

from  StorableConfigBase
protected bool $isNew

Whether the configuration object is new or has been saved to the storage.

from  StorableConfigBase
protected array $originalData

The data of the configuration object.

from  StorableConfigBase
protected EventDispatcherInterface $eventDispatcher

An event dispatcher instance to use for configuration events.

from  Config
protected array $overriddenData

The current runtime data.

from  Config
protected array $moduleOverrides

The current module overrides.

from  Config
protected array $settingsOverrides

The current settings overrides.

from  Config

Methods

__sleep()

{@inheritdoc}

__wakeup()

{@inheritdoc}

$this
setCacheability(CacheableDependencyInterface $cacheability)

Sets cacheability; useful for value object constructors.

getCacheTags()

{@inheritdoc}

addCacheableDependency($other_object)

{@inheritdoc}

addCacheContexts(array $cache_contexts)

{@inheritdoc}

addCacheTags(array $cache_tags)

{@inheritdoc}

string
getName()

Returns the name of this configuration object.

$this
setName(string $name)

Sets the name of this configuration object.

static 
validateName(string $name)

Validates the configuration object name.

mixed
get(string $key = '')

Gets data from this configuration object.

from  Config
$this
setData(array $data)

Replaces the data of this configuration object.

from  Config
$this
set(string $key, mixed $value)

Sets a value in this configuration object.

null
validateKeys(array $data)

Validates all keys in a passed in config array structure.

$this
clear(string $key)

Unsets a value in this configuration object.

$this
merge(array $data_to_merge)

Merges data into a configuration object.

mixed
castSafeStrings(mixed $data)

Casts any objects that implement MarkupInterface to string.

$this
save(bool $has_trusted_data = FALSE)

Saves the configuration object.

$this
delete()

Deletes the configuration object.

$this
initWithData(array $data)

Initializes a configuration object with pre-loaded data.

from  Config
bool
isNew()

Returns whether this configuration object is new.

getStorage()

Retrieves the storage used to load and save this configuration object.

getSchemaWrapper()

Gets the schema wrapper for the whole configuration object.

null
validateValue(string $key, mixed $value)

Validate the values are allowed data types.

mixed
castValue(string|null $key, mixed $value)

Casts the value to correct data type using the configuration schema.

__construct(string $name, StorageInterface $storage, EventDispatcherInterface $event_dispatcher, TypedConfigManagerInterface $typed_config)

Constructs a configuration object.

from  Config
$this
setSettingsOverride(array $data)

Sets settings.php overrides for this configuration object.

from  Config
$this
setModuleOverride(array $data)

Sets module overrides for this configuration object.

from  Config
$this
setOverriddenData()

Sets the current data for this configuration object.

from  Config
$this
resetOverriddenData()

Resets the current data, so overrides are re-applied.

from  Config
array
getRawData()

Gets the raw data without overrides.

from  Config
mixed
getOriginal(string $key = '', bool $apply_overrides = TRUE)

Gets original data from this configuration object.

from  Config
bool
hasOverrides(string $key = '')

Determines if overrides are applied to a key for this configuration object.

from  Config

Details

__sleep()

{@inheritdoc}

__wakeup()

{@inheritdoc}

protected $this setCacheability(CacheableDependencyInterface $cacheability)

Sets cacheability; useful for value object constructors.

Parameters

CacheableDependencyInterface $cacheability

The cacheability to set.

Return Value

$this

getCacheTags()

{@inheritdoc}

getCacheContexts()

{@inheritdoc}

getCacheMaxAge()

{@inheritdoc}

addCacheableDependency($other_object)

{@inheritdoc}

Parameters

$other_object

addCacheContexts(array $cache_contexts)

{@inheritdoc}

Parameters

array $cache_contexts

addCacheTags(array $cache_tags)

{@inheritdoc}

Parameters

array $cache_tags

mergeCacheMaxAge($max_age)

{@inheritdoc}

Parameters

$max_age

string getName()

Returns the name of this configuration object.

Return Value

string

The name of the configuration object.

$this setName(string $name)

Sets the name of this configuration object.

Parameters

string $name

The name of the configuration object.

Return Value

$this

The configuration object.

static validateName(string $name)

Validates the configuration object name.

Parameters

string $name

The name of the configuration object.

Exceptions

ConfigNameException

See also

Config::MAX_NAME_LENGTH

mixed get(string $key = '')

Gets data from this configuration object.

Parameters

string $key

A string that maps to a key within the configuration data. For instance in the following configuration array: @code array( 'foo' => array( 'bar' => 'baz', ), ); @endcode A key of 'foo.bar' would return the string 'baz'. However, a key of 'foo' would return array('bar' => 'baz'). If no key is specified, then the entire data array is returned.

Return Value

mixed

The data that was requested.

$this setData(array $data)

Replaces the data of this configuration object.

Parameters

array $data

The new configuration data.

Return Value

$this

The configuration object.

Exceptions

ConfigValueException

$this set(string $key, mixed $value)

Sets a value in this configuration object.

Parameters

string $key

Identifier to store value in configuration.

mixed $value

Value to associate with identifier.

Return Value

$this

The configuration object.

Exceptions

ConfigValueException

protected null validateKeys(array $data)

Validates all keys in a passed in config array structure.

Parameters

array $data

Configuration array structure.

Return Value

null

Exceptions

ConfigValueException

$this clear(string $key)

Unsets a value in this configuration object.

Parameters

string $key

Name of the key whose value should be unset.

Return Value

$this

The configuration object.

$this merge(array $data_to_merge)

Merges data into a configuration object.

Parameters

array $data_to_merge

An array containing data to merge.

Return Value

$this

The configuration object.

protected mixed castSafeStrings(mixed $data)

Casts any objects that implement MarkupInterface to string.

Parameters

mixed $data

The configuration data.

Return Value

mixed

The data with any safe strings cast to string.

$this save(bool $has_trusted_data = FALSE)

Saves the configuration object.

Must invalidate the cache tags associated with the configuration object.

Parameters

bool $has_trusted_data

Set to TRUE if the configuration data has already been checked to ensure it conforms to schema. Generally this is only used during module and theme installation.

Return Value

$this

$this delete()

Deletes the configuration object.

Return Value

$this

$this initWithData(array $data)

Initializes a configuration object with pre-loaded data.

Parameters

array $data

Array of loaded data for this configuration object.

Return Value

$this

The configuration object.

bool isNew()

Returns whether this configuration object is new.

Return Value

bool

TRUE if this configuration object does not exist in storage.

StorageInterface getStorage()

Retrieves the storage used to load and save this configuration object.

Return Value

StorageInterface

The configuration storage object.

protected Element getSchemaWrapper()

Gets the schema wrapper for the whole configuration object.

The schema wrapper is dependent on the configuration name and the whole data structure, so if the name or the data changes in any way, the wrapper should be reset.

Return Value

Element

protected null validateValue(string $key, mixed $value)

Validate the values are allowed data types.

Parameters

string $key

A string that maps to a key within the configuration data.

mixed $value

Value to associate with the key.

Return Value

null

Exceptions

UnsupportedDataTypeConfigException

protected mixed castValue(string|null $key, mixed $value)

Casts the value to correct data type using the configuration schema.

Parameters

string|null $key

A string that maps to a key within the configuration data. If NULL the top level mapping will be processed.

mixed $value

Value to associate with the key.

Return Value

mixed

The value cast to the type indicated in the schema.

Exceptions

UnsupportedDataTypeConfigException

__construct(string $name, StorageInterface $storage, EventDispatcherInterface $event_dispatcher, TypedConfigManagerInterface $typed_config)

Constructs a configuration object.

Parameters

string $name

The name of the configuration object being constructed.

StorageInterface $storage

A storage object to use for reading and writing the configuration data.

EventDispatcherInterface $event_dispatcher

An event dispatcher instance to use for configuration events.

TypedConfigManagerInterface $typed_config

The typed configuration manager service.

$this setSettingsOverride(array $data)

Sets settings.php overrides for this configuration object.

The overridden data only applies to this configuration object.

Parameters

array $data

The overridden values of the configuration data.

Return Value

$this

The configuration object.

$this setModuleOverride(array $data)

Sets module overrides for this configuration object.

Parameters

array $data

The overridden values of the configuration data.

Return Value

$this

The configuration object.

protected $this setOverriddenData()

Sets the current data for this configuration object.

Configuration overrides operate at two distinct layers: modules and settings.php. Overrides in settings.php take precedence over values provided by modules. Precedence or different module overrides is determined by the priority of the config.factory.override tagged services.

Return Value

$this

The configuration object.

protected $this resetOverriddenData()

Resets the current data, so overrides are re-applied.

This method should be called after the original data or the overridden data has been changed.

Return Value

$this

The configuration object.

array getRawData()

Gets the raw data without overrides.

Return Value

array

The raw data.

mixed getOriginal(string $key = '', bool $apply_overrides = TRUE)

Gets original data from this configuration object.

Original data is the data as it is immediately after loading from configuration storage before any changes. If this is a new configuration object it will be an empty array.

Parameters

string $key

A string that maps to a key within the configuration data.

bool $apply_overrides

Apply any overrides to the original data. Defaults to TRUE.

Return Value

mixed

The data that was requested.

See also

Config::get

bool hasOverrides(string $key = '')

Determines if overrides are applied to a key for this configuration object.

Parameters

string $key

(optional) A string that maps to a key within the configuration data. For instance in the following configuration array: @code array( 'foo' => array( 'bar' => 'baz', ), ); @endcode A key of 'foo.bar' would map to the string 'baz'. However, a key of 'foo' would map to the array('bar' => 'baz'). If not supplied TRUE will be returned if there are any overrides at all for this configuration object.

Return Value

bool

TRUE if there are any overrides for the key, otherwise FALSE.