You are here

class ConfigEventSubscriber in Tome 8

Keeps the config export directory synced with config CRUD operations.

@internal

Hierarchy

  • class \Drupal\tome_sync\EventSubscriber\ConfigEventSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface

Expanded class hierarchy of ConfigEventSubscriber

1 string reference to 'ConfigEventSubscriber'
tome_sync.services.yml in modules/tome_sync/tome_sync.services.yml
modules/tome_sync/tome_sync.services.yml
1 service uses ConfigEventSubscriber
tome_sync.config_event_subscriber in modules/tome_sync/tome_sync.services.yml
Drupal\tome_sync\EventSubscriber\ConfigEventSubscriber

File

modules/tome_sync/src/EventSubscriber/ConfigEventSubscriber.php, line 16

Namespace

Drupal\tome_sync\EventSubscriber
View source
class ConfigEventSubscriber implements EventSubscriberInterface {

  /**
   * The config storage.
   *
   * @var \Drupal\Core\Config\StorageInterface
   */
  protected $configStorage;

  /**
   * Constructs the ConfigEventSubscriber object.
   *
   * @param \Drupal\Core\Config\StorageInterface $config_storage
   *   The config storage.
   */
  public function __construct(StorageInterface $config_storage) {
    $this->configStorage = $config_storage;
  }

  /**
   * Reacts to a save event.
   *
   * @param \Drupal\Core\Config\ConfigCrudEvent $event
   *   The configuration event.
   */
  public function configSave(ConfigCrudEvent $event) {
    if (!\Drupal::isConfigSyncing() && !isset($GLOBALS['_tome_sync_installing'])) {
      $config = $event
        ->getConfig();
      $this->configStorage
        ->write($config
        ->getName(), $config
        ->getRawData());
    }
  }

  /**
   * Reacts to delete event.
   *
   * @param \Drupal\Core\Config\ConfigCrudEvent $event
   *   The configuration event.
   */
  public function configDelete(ConfigCrudEvent $event) {
    if (!\Drupal::isConfigSyncing() && !isset($GLOBALS['_tome_sync_installing'])) {
      $this->configStorage
        ->delete($event
        ->getConfig()
        ->getName());
    }
  }

  /**
   * Reacts to rename event.
   *
   * @param \Drupal\Core\Config\ConfigRenameEvent $event
   *   The configuration event.
   */
  public function configRename(ConfigRenameEvent $event) {
    if (!\Drupal::isConfigSyncing() && !isset($GLOBALS['_tome_sync_installing'])) {
      $this->configStorage
        ->rename($event
        ->getOldName(), $event
        ->getConfig()
        ->getName());
    }
  }

  /**
   * {@inheritdoc}
   */
  public static function getSubscribedEvents() {
    $events[ConfigEvents::SAVE][] = [
      'configSave',
    ];
    $events[ConfigEvents::DELETE][] = [
      'configDelete',
    ];
    $events[ConfigEvents::RENAME][] = [
      'configRename',
    ];
    return $events;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ConfigEventSubscriber::$configStorage protected property The config storage.
ConfigEventSubscriber::configDelete public function Reacts to delete event.
ConfigEventSubscriber::configRename public function Reacts to rename event.
ConfigEventSubscriber::configSave public function Reacts to a save event.
ConfigEventSubscriber::getSubscribedEvents public static function
ConfigEventSubscriber::__construct public function Constructs the ConfigEventSubscriber object.