3 namespace Drupal\config_test\Entity;
5 use Drupal\Core\Config\Entity\ConfigEntityBase;
6 use Drupal\config_test\ConfigTestInterface;
7 use Drupal\Core\Config\Entity\ConfigEntityInterface;
8 use Drupal\Core\Entity\EntityStorageInterface;
11 * Defines the ConfigTest configuration entity.
15 * label = @Translation("Test configuration"),
17 * "storage" = "Drupal\config_test\ConfigTestStorage",
18 * "list_builder" = "Drupal\config_test\ConfigTestListBuilder",
20 * "default" = "Drupal\config_test\ConfigTestForm",
21 * "delete" = "Drupal\Core\Entity\EntityDeleteForm"
23 * "access" = "Drupal\config_test\ConfigTestAccessControlHandler"
25 * config_prefix = "dynamic",
32 * "edit-form" = "/admin/structure/config_test/manage/{config_test}",
33 * "delete-form" = "/admin/structure/config_test/manage/{config_test}/delete",
34 * "enable" = "/admin/structure/config_test/manage/{config_test}/enable",
35 * "disable" = "/admin/structure/config_test/manage/{config_test}/disable",
36 * "collection" = "/admin/structure/config_test",
40 class ConfigTest extends ConfigEntityBase implements ConfigTestInterface {
43 * The machine name for the configuration entity.
50 * The human-readable name of the configuration entity.
57 * The weight of the configuration entity.
64 * The image style to use.
71 * A protected property of the configuration entity.
75 protected $protected_property;
80 public static function sort(ConfigEntityInterface $a, ConfigEntityInterface $b) {
81 \Drupal::state()->set('config_entity_sort', TRUE);
82 return parent::sort($a, $b);
88 public function postSave(EntityStorageInterface $storage, $update = TRUE) {
89 // Used to test secondary writes during config sync.
90 if ($this->id() == 'primary') {
91 $secondary = $storage->create([
93 'label' => 'Secondary Default',
97 if ($this->id() == 'deleter') {
98 $deletee = $storage->load('deletee');
106 public static function postDelete(EntityStorageInterface $storage, array $entities) {
107 parent::postDelete($storage, $entities);
108 foreach ($entities as $entity) {
109 if ($entity->id() == 'deleter') {
110 $deletee = $storage->load('deletee');
119 public function onDependencyRemoval(array $dependencies) {
120 // Record which entities have this method called on.
121 $called = \Drupal::state()->get('config_test.on_dependency_removal_called', []);
122 $called[] = $this->id();
123 \Drupal::state()->set('config_test.on_dependency_removal_called', $called);
125 $changed = parent::onDependencyRemoval($dependencies);
126 if (!isset($this->dependencies['enforced']['config'])) {
129 $fix_deps = \Drupal::state()->get('config_test.fix_dependencies', []);
130 foreach ($dependencies['config'] as $entity) {
131 if (in_array($entity->getConfigDependencyName(), $fix_deps)) {
132 $key = array_search($entity->getConfigDependencyName(), $this->dependencies['enforced']['config']);
133 if ($key !== FALSE) {
135 unset($this->dependencies['enforced']['config'][$key]);
139 // If any of the dependencies removed still exists, return FALSE.
140 if (array_intersect_key(array_flip($this->dependencies['enforced']['config']), $dependencies['config'])) {
147 * Sets the enforced dependencies.
149 * @param array $dependencies
150 * A config dependency array.
154 * @see \Drupal\Core\Config\Entity\ConfigDependencyManager
156 public function setEnforcedDependencies(array $dependencies) {
157 $this->dependencies['enforced'] = $dependencies;
164 public function isInstallable() {
165 return $this->id != 'isinstallable' || \Drupal::state()->get('config_test.isinstallable');