You are here

public function ConfigUpdater::delete in Commerce Core 8.2

Deletes configuration.

Parameters

string[] $config_names: The configuration names.

Return value

\Drupal\commerce\Config\ConfigUpdateResult The result.

Overrides ConfigUpdaterInterface::delete

File

src/Config/ConfigUpdater.php, line 173

Class

ConfigUpdater
Default implementation of the ConfigUpdaterInterface.

Namespace

Drupal\commerce\Config

Code

public function delete(array $config_names) {
  $succeeded = [];
  $failed = [];
  foreach ($config_names as $config_name) {
    if (!$this
      ->loadFromActive($config_name)) {
      $succeeded[$config_name] = $this
        ->t('Skipped: @config does not exist in active storage', [
        '@config' => $config_name,
      ]);
      continue;
    }
    $config_type = $this
      ->getConfigType($config_name);
    if ($config_type == 'system.simple') {
      $this->configFactory
        ->getEditable($config_name)
        ->delete();
    }
    else {

      /** @var \Drupal\Core\Config\Entity\ConfigEntityTypeInterface $entity_type */
      $entity_type = $this->entityTypeManager
        ->getDefinition($config_type);
      $id = substr($config_name, strlen($entity_type
        ->getConfigPrefix()) + 1);

      /** @var \Drupal\Core\Config\Entity\ConfigEntityStorageInterface $entity_storage */
      $entity_storage = $this->entityTypeManager
        ->getStorage($config_type);
      $entity = $entity_storage
        ->load($id);
      $entity_storage
        ->delete([
        $entity,
      ]);
    }
    $succeeded[$config_name] = $this
      ->t('@config was successfully deleted', [
      '@config' => $config_name,
    ]);
  }
  return new ConfigUpdateResult($succeeded, $failed);
}