class ConfigTest

Same name in this branch
  1. 9 core/modules/migrate_drupal/tests/src/Kernel/Plugin/migrate/source/d8/ConfigTest.php \Drupal\Tests\migrate_drupal\Kernel\Plugin\migrate\source\d8\ConfigTest
  2. 9 core/modules/migrate/tests/src/Unit/destination/ConfigTest.php \Drupal\Tests\migrate\Unit\destination\ConfigTest
  3. 9 core/modules/system/tests/src/Functional/File/ConfigTest.php \Drupal\Tests\system\Functional\File\ConfigTest
  4. 9 core/tests/Drupal/Tests/Composer/Plugin/ProjectMessage/ConfigTest.php \Drupal\Tests\Composer\Plugin\ProjectMessage\ConfigTest
  5. 9 core/tests/Drupal/Tests/Composer/Plugin/VendorHardening/ConfigTest.php \Drupal\Tests\Composer\Plugin\VendorHardening\ConfigTest
  6. 9 core/tests/Drupal/Tests/Core/Config/ConfigTest.php \Drupal\Tests\Core\Config\ConfigTest
Same name and namespace in other branches
  1. 11.x core/modules/migrate_drupal/tests/src/Kernel/Plugin/migrate/source/d8/ConfigTest.php \Drupal\Tests\migrate_drupal\Kernel\Plugin\migrate\source\d8\ConfigTest
  2. 11.x core/modules/config/tests/config_test/src/Entity/ConfigTest.php \Drupal\config_test\Entity\ConfigTest
  3. 11.x core/modules/migrate/tests/src/Unit/destination/ConfigTest.php \Drupal\Tests\migrate\Unit\destination\ConfigTest
  4. 11.x core/modules/system/tests/src/Functional/File/ConfigTest.php \Drupal\Tests\system\Functional\File\ConfigTest
  5. 11.x core/tests/Drupal/Tests/Composer/Plugin/ProjectMessage/ConfigTest.php \Drupal\Tests\Composer\Plugin\ProjectMessage\ConfigTest
  6. 11.x core/tests/Drupal/Tests/Composer/Plugin/VendorHardening/ConfigTest.php \Drupal\Tests\Composer\Plugin\VendorHardening\ConfigTest
  7. 11.x core/tests/Drupal/Tests/Core/Config/ConfigTest.php \Drupal\Tests\Core\Config\ConfigTest

Defines the ConfigTest configuration entity.

Plugin annotation


@ConfigEntityType(
  id = "config_test",
  label = @Translation("Test configuration"),
  handlers = {
    "storage" = "Drupal\config_test\ConfigTestStorage",
    "list_builder" = "Drupal\config_test\ConfigTestListBuilder",
    "form" = {
      "default" = "Drupal\config_test\ConfigTestForm",
      "delete" = "Drupal\Core\Entity\EntityDeleteForm"
    },
    "access" = "Drupal\config_test\ConfigTestAccessControlHandler"
  },
  config_prefix = "dynamic",
  entity_keys = {
    "id" = "id",
    "label" = "label",
    "status" = "status"
  },
  config_export = {
    "id",
    "label",
    "weight",
    "style",
    "size",
    "size_value",
    "protected_property",
  },
  links = {
    "edit-form" = "/admin/structure/config_test/manage/{config_test}",
    "delete-form" = "/admin/structure/config_test/manage/{config_test}/delete",
    "enable" = "/admin/structure/config_test/manage/{config_test}/enable",
    "disable" = "/admin/structure/config_test/manage/{config_test}/disable",
    "collection" = "/admin/structure/config_test",
  }
)

Hierarchy

Expanded class hierarchy of ConfigTest

6 files declare their use of ConfigTest
ConfigEntityListTest.php in core/modules/config/tests/src/Functional/ConfigEntityListTest.php
ConfigInstallWebTest.php in core/modules/config/tests/src/Functional/ConfigInstallWebTest.php
ConfigTestController.php in core/modules/config/tests/config_test/src/ConfigTestController.php
ConfigTestResourceTestBase.php in core/modules/config/tests/config_test/tests/src/Functional/Rest/ConfigTestResourceTestBase.php
ConfigTestTest.php in core/modules/jsonapi/tests/src/Functional/ConfigTestTest.php

... See full list

File

core/modules/config/tests/config_test/src/Entity/ConfigTest.php, line 49

Namespace

Drupal\config_test\Entity
View source
class ConfigTest extends ConfigEntityBase implements ConfigTestInterface {
  
  /**
   * The machine name for the configuration entity.
   *
   * @var string
   */
  protected $id;
  
  /**
   * The human-readable name of the configuration entity.
   *
   * @var string
   */
  public $label;
  
  /**
   * The weight of the configuration entity.
   *
   * @var int
   */
  public $weight = 0;
  
  /**
   * The image style to use.
   *
   * @var string
   */
  public $style;
  
  /**
   * A protected property of the configuration entity.
   *
   * @var string
   */
  protected $protected_property;
  
  /**
   * {@inheritdoc}
   */
  public static function sort(ConfigEntityInterface $a, ConfigEntityInterface $b) {
    \Drupal::state()->set('config_entity_sort', TRUE);
    return parent::sort($a, $b);
  }
  
  /**
   * {@inheritdoc}
   */
  public function postSave(EntityStorageInterface $storage, $update = TRUE) {
    // Used to test secondary writes during config sync.
    if ($this->id() == 'primary') {
      $secondary = $storage->create([
        'id' => 'secondary',
        'label' => 'Secondary Default',
      ]);
      $secondary->save();
    }
    if ($this->id() == 'deleter') {
      $deletee = $storage->load('deletee');
      $deletee->delete();
    }
  }
  
  /**
   * {@inheritdoc}
   */
  public static function postDelete(EntityStorageInterface $storage, array $entities) {
    parent::postDelete($storage, $entities);
    foreach ($entities as $entity) {
      if ($entity->id() == 'deleter') {
        $deletee = $storage->load('deletee');
        $deletee->delete();
      }
    }
  }
  
  /**
   * {@inheritdoc}
   */
  public function calculateDependencies() {
    parent::calculateDependencies();
    if ($module = \Drupal::state()->get('config_test_new_dependency', FALSE)) {
      $this->addDependency('module', $module);
    }
    return $this;
  }
  
  /**
   * {@inheritdoc}
   */
  public function onDependencyRemoval(array $dependencies) {
    // Record which entities have this method called on and what dependencies
    // are passed.
    $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 any of the dependencies removed still exists, return FALSE.
    if (array_intersect_key(array_flip($this->dependencies['enforced']['config']), $dependencies['config'])) {
      return FALSE;
    }
    return $changed;
  }
  
  /**
   * Sets the enforced dependencies.
   *
   * @param array $dependencies
   *   A config dependency array.
   *
   * @return $this
   *
   * @see \Drupal\Core\Config\Entity\ConfigDependencyManager
   */
  public function setEnforcedDependencies(array $dependencies) {
    $this->dependencies['enforced'] = $dependencies;
    return $this;
  }
  
  /**
   * {@inheritdoc}
   */
  public function isInstallable() {
    return $this->id != 'isinstallable' || \Drupal::state()->get('config_test.isinstallable');
  }

}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.