You are here

class DefaultContentConfigSubscriber in Default Content for D8 8

Same name and namespace in other branches
  1. 2.0.x src/Config/DefaultContentConfigSubscriber.php \Drupal\default_content\Config\DefaultContentConfigSubscriber

Reacts to configuration events for the Default Content module.

Hierarchy

Expanded class hierarchy of DefaultContentConfigSubscriber

1 string reference to 'DefaultContentConfigSubscriber'
default_content.services.yml in ./default_content.services.yml
default_content.services.yml
1 service uses DefaultContentConfigSubscriber
default_content.config_subscriber in ./default_content.services.yml
Drupal\default_content\Config\DefaultContentConfigSubscriber

File

src/Config/DefaultContentConfigSubscriber.php, line 13

Namespace

Drupal\default_content\Config
View source
class DefaultContentConfigSubscriber implements EventSubscriberInterface {

  /**
   * The default content importer.
   *
   * @var \Drupal\default_content\ImporterInterface
   */
  protected $defaultContentImporter;

  /**
   * Constructs a DefaultContentConfigSubscriber object.
   *
   * @param \Drupal\default_content\ImporterInterface $default_content_importer
   *   The default content importer.
   */
  public function __construct(ImporterInterface $default_content_importer) {
    $this->defaultContentImporter = $default_content_importer;
  }

  /**
   * Creates default content after config synchronization.
   *
   * @param \Drupal\Core\Config\ConfigImporterEvent $event
   *   The config importer event.
   */
  public function onConfigImport(ConfigImporterEvent $event) {
    $modules = $event
      ->getConfigImporter()
      ->getExtensionChangelist('module', 'install');
    foreach ($modules as $module) {
      $this->defaultContentImporter
        ->importContent($module);
    }
  }

  /**
   * {@inheritdoc}
   */
  public static function getSubscribedEvents() {
    return [
      ConfigEvents::IMPORT => 'onConfigImport',
    ];
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DefaultContentConfigSubscriber::$defaultContentImporter protected property The default content importer.
DefaultContentConfigSubscriber::getSubscribedEvents public static function Returns an array of event names this subscriber wants to listen to.
DefaultContentConfigSubscriber::onConfigImport public function Creates default content after config synchronization.
DefaultContentConfigSubscriber::__construct public function Constructs a DefaultContentConfigSubscriber object.