You are here

class ConfigSubscriber in Group 8

Same name and namespace in other branches
  1. 2.0.x src/EventSubscriber/ConfigSubscriber.php \Drupal\group\EventSubscriber\ConfigSubscriber

Reacts to configuration imports.

Hierarchy

  • class \Drupal\group\EventSubscriber\ConfigSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface

Expanded class hierarchy of ConfigSubscriber

1 string reference to 'ConfigSubscriber'
group.services.yml in ./group.services.yml
group.services.yml
1 service uses ConfigSubscriber
group.config_subscriber in ./group.services.yml
Drupal\group\EventSubscriber\ConfigSubscriber

File

src/EventSubscriber/ConfigSubscriber.php, line 14

Namespace

Drupal\group\EventSubscriber
View source
class ConfigSubscriber implements EventSubscriberInterface {

  /**
   * The entity type manager.
   *
   * @var \Drupal\Core\Entity\EntityTypeManagerInterface
   */
  protected $entityTypeManager;

  /**
   * The group content enabler plugin manager.
   *
   * @var \Drupal\group\Plugin\GroupContentEnablerManagerInterface
   */
  protected $pluginManager;

  /**
   * Constructs a new ConfigSubscriber object.
   *
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
   *   The entity type manager.
   * @param \Drupal\group\Plugin\GroupContentEnablerManagerInterface $plugin_manager
   *   The group content enabler plugin manager.
   */
  public function __construct(EntityTypeManagerInterface $entity_type_manager, GroupContentEnablerManagerInterface $plugin_manager) {
    $this->entityTypeManager = $entity_type_manager;
    $this->pluginManager = $plugin_manager;
  }

  /**
   * Causes a group role synchronization after importing config.
   *
   * @param \Drupal\Core\Config\ConfigImporterEvent $event
   *   The configuration event.
   */
  public function onConfigImport(ConfigImporterEvent $event) {
    $this->pluginManager
      ->installEnforced();

    /** @var \Drupal\group\Entity\Storage\GroupRoleStorageInterface $storage */
    $storage = $this->entityTypeManager
      ->getStorage('group_role');
    $storage
      ->createInternal();
    $storage
      ->createSynchronized();
  }

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

}

Members

Namesort descending Modifiers Type Description Overrides
ConfigSubscriber::$entityTypeManager protected property The entity type manager.
ConfigSubscriber::$pluginManager protected property The group content enabler plugin manager.
ConfigSubscriber::getSubscribedEvents public static function Returns an array of event names this subscriber wants to listen to.
ConfigSubscriber::onConfigImport public function Causes a group role synchronization after importing config.
ConfigSubscriber::__construct public function Constructs a new ConfigSubscriber object.