You are here

class LanguageConfigEventSubscriber in Tome 8

Keeps the config export directory synced with language config operations.

@internal

Hierarchy

Expanded class hierarchy of LanguageConfigEventSubscriber

1 file declares its use of LanguageConfigEventSubscriber
TomeSyncServiceProvider.php in modules/tome_sync/src/TomeSyncServiceProvider.php

File

modules/tome_sync/src/EventSubscriber/LanguageConfigEventSubscriber.php, line 15

Namespace

Drupal\tome_sync\EventSubscriber
View source
class LanguageConfigEventSubscriber 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\language\Config\LanguageConfigOverrideCrudEvent $event
   *   The configuration event.
   */
  public function configSave(LanguageConfigOverrideCrudEvent $event) {
    if (!\Drupal::isConfigSyncing()) {
      $override = $event
        ->getLanguageConfigOverride();
      $collection = $this->configStorage
        ->createCollection($override
        ->getStorage()
        ->getCollectionName());
      $name = $override
        ->getName();
      $collection
        ->write($name, $override
        ->get());
    }
  }

  /**
   * Reacts to delete event.
   *
   * @param \Drupal\language\Config\LanguageConfigOverrideCrudEvent $event
   *   The configuration event.
   */
  public function configDelete(LanguageConfigOverrideCrudEvent $event) {
    if (!\Drupal::isConfigSyncing()) {
      $override = $event
        ->getLanguageConfigOverride();
      $collection = $this->configStorage
        ->createCollection($override
        ->getStorage()
        ->getCollectionName());
      $name = $override
        ->getName();
      $collection
        ->delete($name);
    }
  }

  /**
   * {@inheritdoc}
   */
  public static function getSubscribedEvents() {
    $events[LanguageConfigOverrideEvents::SAVE_OVERRIDE][] = [
      'configSave',
    ];
    $events[LanguageConfigOverrideEvents::DELETE_OVERRIDE][] = [
      'configDelete',
    ];
    return $events;
  }

}

Members

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