class BackgroundImageSettings in Background Image 8
Same name and namespace in other branches
- 2.x src/BackgroundImageSettings.php \Drupal\background_image\BackgroundImageSettings
- 2.0.x src/BackgroundImageSettings.php \Drupal\background_image\BackgroundImageSettings
Hierarchy
- class \Drupal\Core\Config\ConfigBase implements RefinableCacheableDependencyInterface uses RefinableCacheableDependencyTrait, DependencySerializationTrait
- class \Drupal\Core\Config\StorableConfigBase
- class \Drupal\background_image\BackgroundImageSettings
- class \Drupal\Core\Config\StorableConfigBase
Expanded class hierarchy of BackgroundImageSettings
1 file declares its use of BackgroundImageSettings
- BackgroundImage.php in src/
Entity/ BackgroundImage.php
File
- src/
BackgroundImageSettings.php, line 11
Namespace
Drupal\background_imageView source
class BackgroundImageSettings extends StorableConfigBase {
/**
* Overridden data.
*
* @var array
*/
protected $overriddenData;
/**
* {@inheritdoc}
*/
public function __construct() {
$this->name = 'background_image.settings.fake';
$this->typedConfigManager = \Drupal::service('config.typed');
}
/**
* {@inheritdoc}
*/
public function delete() {
throw new ImmutableConfigException("Can not delete immutable configuration {$this->getName()}. This config is automatically stored in the \\Drupal\\background_image\\Entity\\BackgroundImage entity.");
}
/**
* {@inheritdoc}
*/
public function save($has_trusted_data = FALSE) {
throw new ImmutableConfigException("Can not save immutable configuration {$this->getName()}. This config is automatically handled by the \\Drupal\\background_image\\Entity\\BackgroundImage entity.");
}
/**
* Retrieves the data currently set as a drupalSettings array.
*
* @param string $name
* A specific setting to retrieve. If not set, the entire settings array
* will be returned.
*
* @return array
* The data.
*/
public function drupalSettings($name = '') {
$data = self::snakeCaseToCamelCase(empty($name) ? $this
->get() : [
$name => $this
->get($name),
]);
if (empty($name)) {
return $data;
}
return reset($data);
}
public function getOriginal($key = '') {
if (empty($key)) {
return $this->originalData;
}
else {
$parts = explode('.', $key);
if (count($parts) == 1) {
return isset($this->originalData[$key]) ? $this->originalData[$key] : NULL;
}
else {
$value = NestedArray::getValue($this->originalData, $parts, $key_exists);
return $key_exists ? $value : NULL;
}
}
}
public function getOverridden($key = '') {
// Whole overridden array.
if (empty($key)) {
return $this->overriddenData;
}
// Top level key.
$parts = explode('.', $key);
if (count($parts) == 1) {
return isset($this->overriddenData[$key]) ? $this->overriddenData[$key] : NULL;
}
// Nested key.
$value = NestedArray::getValue($this->overriddenData, $parts, $key_exists);
return $key_exists ? $value : NULL;
}
/**
* {@inheritdoc}
*/
public function initWithData(array $data) {
$this->isNew = FALSE;
// Set initial data to default settings for casting to work (needs keys).
$this->data = $data;
// Now cast initial data to ensure proper values.
$this
->merge($data);
// Indicate this is the original data.
$this->originalData = $this->data;
// Set initial overridden data to an empty array.
$this->overriddenData = [];
return $this;
}
/**
* @param string $key
*
* @return bool
* TRUE or FALSE
*/
public function isOverridden($key = NULL) {
return !empty($this
->getOverridden($key));
}
/**
* {@inheritdoc}
*/
public function merge(array $data_to_merge) {
foreach ($data_to_merge as $key => $value) {
$this
->set($key, $value);
}
return $this;
}
/**
* {@inheritdoc}
*/
public function set($key, $value) {
// The schema wrapper depends on the most recent data structure to cast
// values. It must be reset every time a value has changed to properly cast.
$this->schemaWrapper = NULL;
// Ensure all MarkupInterface objects are cast to strings.
$value = $this
->castSafeStrings($value);
// The dot/period is a reserved character; it may appear between keys, but
// not within keys.
if (is_array($value)) {
$this
->validateKeys($value);
}
$parts = explode('.', $key);
$nested = count($parts) > 1;
if ($nested) {
// For casting to work properly, the raw value must first be set.
NestedArray::setValue($this->data, $parts, $value);
// Now cast the value and set it again.
$value = $this
->castValue($key, $value);
NestedArray::setValue($this->data, $parts, $value);
}
else {
// For casting to work properly, the raw value must first be set.
$this->data[$key] = $value;
// Now cast the value and set it again.
$value = $this
->castValue($key, $value);
$this->data[$key] = $value;
}
// Determine if value overrides original data.
$overridden_value = NULL;
if ($this->originalData) {
$overridden_value = $value;
$original_value = $this
->getOriginal($key);
if (is_array($value) && is_array($original_value)) {
if ($diff_value = DiffArray::diffAssocRecursive($value, $original_value)) {
$overridden_value = $value;
}
}
if (isset($overridden_value) && $overridden_value !== $original_value) {
if ($nested) {
NestedArray::setValue($this->overriddenData, $parts, $overridden_value);
}
else {
$this->overriddenData[$key] = $overridden_value;
}
}
elseif ($nested) {
NestedArray::unsetValue($this->overriddenData, $parts);
}
else {
unset($this->overriddenData[$key]);
}
}
return $this;
}
/**
* Converts snake_case_keys into camelCaseKeys.
*
* @param array $array
* An array to iterate over.
*
* @return array
* The converted array.
*/
protected static function snakeCaseToCamelCase(array $array = []) {
$converter = new CamelCaseToSnakeCaseNameConverter();
$data = [];
foreach ($array as $key => $value) {
$data[$converter
->denormalize($key)] = is_array($value) ? self::snakeCaseToCamelCase($value) : $value;
}
ksort($data);
return $data;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
BackgroundImageSettings:: |
protected | property | Overridden data. | |
BackgroundImageSettings:: |
public | function |
Deletes the configuration object. Overrides StorableConfigBase:: |
|
BackgroundImageSettings:: |
public | function | Retrieves the data currently set as a drupalSettings array. | |
BackgroundImageSettings:: |
public | function | ||
BackgroundImageSettings:: |
public | function | ||
BackgroundImageSettings:: |
public | function |
Initializes a configuration object with pre-loaded data. Overrides StorableConfigBase:: |
|
BackgroundImageSettings:: |
public | function | ||
BackgroundImageSettings:: |
public | function |
Merges data into a configuration object. Overrides ConfigBase:: |
|
BackgroundImageSettings:: |
public | function |
Saves the configuration object. Overrides StorableConfigBase:: |
|
BackgroundImageSettings:: |
public | function |
Sets a value in this configuration object. Overrides ConfigBase:: |
|
BackgroundImageSettings:: |
protected static | function | Converts snake_case_keys into camelCaseKeys. | |
BackgroundImageSettings:: |
public | function | ||
CacheableDependencyTrait:: |
protected | property | Cache contexts. | |
CacheableDependencyTrait:: |
protected | property | Cache max-age. | |
CacheableDependencyTrait:: |
protected | property | Cache tags. | |
CacheableDependencyTrait:: |
protected | function | Sets cacheability; useful for value object constructors. | |
ConfigBase:: |
protected | property | The data of the configuration object. | |
ConfigBase:: |
protected | property | The name of the configuration object. | |
ConfigBase:: |
protected | function | Casts any objects that implement MarkupInterface to string. | |
ConfigBase:: |
public | function | Unsets a value in this configuration object. | 1 |
ConfigBase:: |
public | function | Gets data from this configuration object. | 1 |
ConfigBase:: |
public | function |
The cache contexts associated with this object. Overrides CacheableDependencyTrait:: |
|
ConfigBase:: |
public | function |
The maximum age for which this object may be cached. Overrides CacheableDependencyTrait:: |
|
ConfigBase:: |
public | function |
The cache tags associated with this object. Overrides CacheableDependencyTrait:: |
1 |
ConfigBase:: |
public | function | Returns the name of this configuration object. | |
ConfigBase:: |
constant | The maximum length of a configuration object name. | ||
ConfigBase:: |
public | function | Replaces the data of this configuration object. | 1 |
ConfigBase:: |
public | function | Sets the name of this configuration object. | |
ConfigBase:: |
protected | function | Validates all keys in a passed in config array structure. | |
ConfigBase:: |
public static | function | Validates the configuration object name. | |
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
RefinableCacheableDependencyTrait:: |
public | function | 1 | |
RefinableCacheableDependencyTrait:: |
public | function | ||
RefinableCacheableDependencyTrait:: |
public | function | ||
RefinableCacheableDependencyTrait:: |
public | function | ||
StorableConfigBase:: |
protected | property | Whether the configuration object is new or has been saved to the storage. | |
StorableConfigBase:: |
protected | property | The data of the configuration object. | |
StorableConfigBase:: |
protected | property | The config schema wrapper object for this configuration object. | |
StorableConfigBase:: |
protected | property | The storage used to load and save this configuration object. | |
StorableConfigBase:: |
protected | property | The typed config manager. | |
StorableConfigBase:: |
protected | function | Casts the value to correct data type using the configuration schema. | |
StorableConfigBase:: |
protected | function | Gets the schema wrapper for the whole configuration object. | |
StorableConfigBase:: |
public | function | Retrieves the storage used to load and save this configuration object. | |
StorableConfigBase:: |
public | function | Returns whether this configuration object is new. | |
StorableConfigBase:: |
protected | function | Validate the values are allowed data types. |