function CheckpointStorage::onConfigSaveAndDelete

Same name in other branches
  1. 11.x core/lib/Drupal/Core/Config/Checkpoint/CheckpointStorage.php \Drupal\Core\Config\Checkpoint\CheckpointStorage::onConfigSaveAndDelete()

Updates checkpoint when configuration is saved.

Parameters

\Drupal\Core\Config\ConfigCrudEvent $event: The configuration event.

File

core/lib/Drupal/Core/Config/Checkpoint/CheckpointStorage.php, line 353

Class

CheckpointStorage
Provides a config storage that can make checkpoints.

Namespace

Drupal\Core\Config\Checkpoint

Code

public function onConfigSaveAndDelete(ConfigCrudEvent $event) : void {
    $active_checkpoint = $this->checkpoints
        ->getActiveCheckpoint();
    if ($active_checkpoint === NULL) {
        return;
    }
    $saved_config = $event->getConfig();
    $collection = $saved_config->getStorage()
        ->getCollectionName();
    $this->storeCollectionName($collection);
    $key_value = $this->getKeyValue($active_checkpoint->id, $collection);
    // If we have not yet stored a checkpoint for this configuration we should.
    if ($key_value->get($saved_config->getName()) === NULL) {
        $original_data = $this->getOriginalConfig($saved_config);
        // An empty array indicates that the config has to be new as a sequence
        // cannot be the root of a config object. We need to make this assumption
        // because $saved_config->isNew() will always return FALSE here.
        if (empty($original_data)) {
            $original_data = FALSE;
        }
        // Only save change to state if there is a change, even if it's just keys
        // being re-ordered.
        if ($original_data !== $saved_config->getRawData()) {
            $key_value->set($saved_config->getName(), $original_data);
        }
    }
}

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