ConfigImportSubscriber.php 1.15 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php

/**
 * @file
 * Contains \Drupal\Core\EventSubscriber\ConfigImportSubscriber.
 */

namespace Drupal\Core\EventSubscriber;

use Drupal\Core\Config\Config;
use Drupal\Core\Config\ConfigImporterEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;


/**
 * Config import subscriber for config import events.
 */
class ConfigImportSubscriber implements EventSubscriberInterface {

  /**
   * Validates the configuration to be imported.
   *
   * @param \Drupal\Core\Config\ConfigImporterEvent $event
   *   The Event to process.
   *
   * @throws \Drupal\Core\Config\ConfigNameException
   */
  public function onConfigImporterValidate(ConfigImporterEvent $event) {
    foreach (array('delete', 'create', 'update') as $op) {
      foreach ($event->getConfigImporter()->getUnprocessed($op) as $name) {
        Config::validateName($name);
      }
    }
  }

  /**
   * Registers the methods in this class that should be listeners.
   *
   * @return array
   *   An array of event listener definitions.
   */
  static function getSubscribedEvents() {
    $events['config.importer.validate'][] = array('onConfigImporterValidate', 40);
    return $events;
  }

}