abstract class StorableConfigBase extends ConfigBase (View source)

Provides a base class for configuration objects with storage support.

Encapsulates all capabilities needed for configuration handling for a specific configuration object, including storage and data type casting.

The default implementation in \Drupal\Core\Config\Config adds support for runtime overrides. Extend from StorableConfigBase directly to manage configuration with a storage backend that does not support overrides.

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.

protected Element $schemaWrapper

The config schema wrapper object for this configuration object.

protected TypedConfigManagerInterface $typedConfigManager

The typed config manager.

protected bool $isNew

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

protected array $originalData

The data of the configuration object.

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.

$this
setData(array $data)

Replaces the data of this configuration object.

$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.

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.

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.

abstract $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

See also

ConfigInstaller::createConfiguration

abstract $this delete()

Deletes the configuration object.

Must invalidate the cache tags associated with 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