Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
Total | |
0.00% |
0 / 1 |
|
25.00% |
1 / 4 |
CRAP | |
68.18% |
15 / 22 |
LanguageConfigOverride | |
0.00% |
0 / 1 |
|
25.00% |
1 / 4 |
7.16 | |
68.18% |
15 / 22 |
__construct | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 5 |
|||
save | |
0.00% |
0 / 1 |
3.01 | |
88.89% |
8 / 9 |
|||
delete | |
100.00% |
1 / 1 |
1 | |
100.00% |
7 / 7 |
|||
getLangcode | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 1 |
<?php | |
/** | |
* @file | |
* Contains \Drupal\language\Config\LanguageConfigOverride. | |
*/ | |
namespace Drupal\language\Config; | |
use Drupal\Core\Cache\Cache; | |
use Drupal\Core\Config\StorableConfigBase; | |
use Drupal\Core\Config\StorageInterface; | |
use Drupal\Core\Config\TypedConfigManagerInterface; | |
use Symfony\Component\EventDispatcher\EventDispatcherInterface; | |
/** | |
* Defines language configuration overrides. | |
*/ | |
class LanguageConfigOverride extends StorableConfigBase { | |
use LanguageConfigCollectionNameTrait; | |
/** | |
* The event dispatcher. | |
* | |
* @var \Symfony\Component\EventDispatcher\EventDispatcherInterface | |
*/ | |
protected $eventDispatcher; | |
/** | |
* Constructs a language override object. | |
* | |
* @param string $name | |
* The name of the configuration object being overridden. | |
* @param \Drupal\Core\Config\StorageInterface $storage | |
* A storage controller object to use for reading and writing the | |
* configuration override. | |
* @param \Drupal\Core\Config\TypedConfigManagerInterface $typed_config | |
* The typed configuration manager service. | |
* @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $event_dispatcher | |
* The event dispatcher. | |
*/ | |
public function __construct($name, StorageInterface $storage, TypedConfigManagerInterface $typed_config, EventDispatcherInterface $event_dispatcher) { | |
$this->name = $name; | |
$this->storage = $storage; | |
$this->typedConfigManager = $typed_config; | |
$this->eventDispatcher = $event_dispatcher; | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
public function save($has_trusted_data = FALSE) { | |
if (!$has_trusted_data) { | |
// @todo Use configuration schema to validate. | |
// https://www.drupal.org/node/2270399 | |
// Perform basic data validation. | |
foreach ($this->data as $key => $value) { | |
$this->validateValue($key, $value); | |
} | |
} | |
$this->storage->write($this->name, $this->data); | |
// Invalidate the cache tags not only when updating, but also when creating, | |
// because a language config override object uses the same cache tag as the | |
// default configuration object. Hence creating a language override is like | |
// an update of configuration, but only for a specific language. | |
Cache::invalidateTags($this->getCacheTags()); | |
$this->isNew = FALSE; | |
$this->eventDispatcher->dispatch(LanguageConfigOverrideEvents::SAVE_OVERRIDE, new LanguageConfigOverrideCrudEvent($this)); | |
$this->originalData = $this->data; | |
return $this; | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
public function delete() { | |
$this->data = array(); | |
$this->storage->delete($this->name); | |
Cache::invalidateTags($this->getCacheTags()); | |
$this->isNew = TRUE; | |
$this->eventDispatcher->dispatch(LanguageConfigOverrideEvents::DELETE_OVERRIDE, new LanguageConfigOverrideCrudEvent($this)); | |
$this->originalData = $this->data; | |
return $this; | |
} | |
/** | |
* Returns the language code of this language override. | |
* | |
* @return string | |
* The language code. | |
*/ | |
public function getLangcode() { | |
return $this->getLangcodeFromCollectionName($this->getStorage()->getCollectionName()); | |
} | |
} |