Same filename in this branch
- 10 core/tests/Drupal/Tests/Core/Config/ConfigTest.php
- 10 core/modules/config/tests/config_test/src/Entity/ConfigTest.php
- 10 core/modules/migrate/tests/src/Unit/destination/ConfigTest.php
- 10 core/modules/system/tests/src/Functional/File/ConfigTest.php
- 10 core/tests/Drupal/Tests/Composer/Plugin/ProjectMessage/ConfigTest.php
- 10 core/tests/Drupal/Tests/Composer/Plugin/VendorHardening/ConfigTest.php
- 10 core/modules/migrate_drupal/tests/src/Kernel/Plugin/migrate/source/d8/ConfigTest.php
Same filename and directory in other branches
- 8.9.x core/modules/config/tests/config_test/src/Entity/ConfigTest.php
- 9 core/modules/config/tests/config_test/src/Entity/ConfigTest.php
Namespace
Drupal\config_test\Entity
File
core/modules/config/tests/config_test/src/Entity/ConfigTest.php
View source
<?php
namespace Drupal\config_test\Entity;
use Drupal\Core\Config\Entity\ConfigEntityBase;
use Drupal\config_test\ConfigTestInterface;
use Drupal\Core\Config\Entity\ConfigEntityInterface;
use Drupal\Core\Entity\EntityStorageInterface;
class ConfigTest extends ConfigEntityBase implements ConfigTestInterface {
protected $id;
public $label;
public $weight = 0;
public $style;
protected $protected_property;
public static function sort(ConfigEntityInterface $a, ConfigEntityInterface $b) {
\Drupal::state()
->set('config_entity_sort', TRUE);
return parent::sort($a, $b);
}
public function postSave(EntityStorageInterface $storage, $update = TRUE) {
if ($this
->id() == 'primary') {
$secondary = $storage
->create([
'id' => 'secondary',
'label' => 'Secondary Default',
]);
$secondary
->save();
}
if ($this
->id() == 'dependency') {
$dependent = $storage
->load('dependent');
$dependent
->delete();
}
}
public static function postDelete(EntityStorageInterface $storage, array $entities) {
parent::postDelete($storage, $entities);
foreach ($entities as $entity) {
if ($entity
->id() == 'dependency') {
$dependent = $storage
->load('dependent');
$dependent
->delete();
}
}
}
public function calculateDependencies() {
parent::calculateDependencies();
if ($module = \Drupal::state()
->get('config_test_new_dependency', FALSE)) {
$this
->addDependency('module', $module);
}
return $this;
}
public function onDependencyRemoval(array $dependencies) {
$called = \Drupal::state()
->get('config_test.on_dependency_removal_called', []);
$called[$this
->id()] = $dependencies;
$called[$this
->id()]['config'] = array_keys($called[$this
->id()]['config']);
$called[$this
->id()]['content'] = array_keys($called[$this
->id()]['content']);
\Drupal::state()
->set('config_test.on_dependency_removal_called', $called);
$changed = parent::onDependencyRemoval($dependencies);
if (!isset($this->dependencies['enforced']['config'])) {
return $changed;
}
$fix_deps = \Drupal::state()
->get('config_test.fix_dependencies', []);
foreach ($dependencies['config'] as $entity) {
if (in_array($entity
->getConfigDependencyName(), $fix_deps)) {
$key = array_search($entity
->getConfigDependencyName(), $this->dependencies['enforced']['config']);
if ($key !== FALSE) {
$changed = TRUE;
unset($this->dependencies['enforced']['config'][$key]);
}
}
}
if (array_intersect_key(array_flip($this->dependencies['enforced']['config']), $dependencies['config'])) {
return FALSE;
}
return $changed;
}
public function setEnforcedDependencies(array $dependencies) {
$this->dependencies['enforced'] = $dependencies;
return $this;
}
public function isInstallable() {
return $this->id != 'isinstallable' || \Drupal::state()
->get('config_test.isinstallable');
}
}
Classes
Name |
Description |
ConfigTest |
Defines the ConfigTest configuration entity. |