You are here

class ConfigSubscriber in Group 2.0.x

Same name and namespace in other branches
  1. 8 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 relation plugin manager.
   *
   * @var \Drupal\group\Plugin\Group\Relation\GroupRelationManagerInterface
   */
  protected $pluginManager;

  /**
   * Constructs a new ConfigSubscriber object.
   *
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
   *   The entity type manager.
   * @param \Drupal\group\Plugin\Group\Relation\GroupRelationManagerInterface $plugin_manager
   *   The group relation plugin manager.
   */
  public function __construct(EntityTypeManagerInterface $entity_type_manager, GroupRelationManagerInterface $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 relation plugin manager.
ConfigSubscriber::getSubscribedEvents public static function
ConfigSubscriber::onConfigImport public function Causes a group role synchronization after importing config.
ConfigSubscriber::__construct public function Constructs a new ConfigSubscriber object.