You are here

class RouteSubscriber in Sitewide Alert 8

Class RouteSubscriber.

Listens to the dynamic route events.

Hierarchy

  • class \Drupal\Core\Routing\RouteSubscriberBase implements \Symfony\Component\EventDispatcher\EventSubscriberInterface

Expanded class hierarchy of RouteSubscriber

1 string reference to 'RouteSubscriber'
sitewide_alert.services.yml in ./sitewide_alert.services.yml
sitewide_alert.services.yml
1 service uses RouteSubscriber
sitewide_alert.route_subscriber in ./sitewide_alert.services.yml
Drupal\sitewide_alert\Routing\RouteSubscriber

File

src/Routing/RouteSubscriber.php, line 14

Namespace

Drupal\sitewide_alert\Routing
View source
class RouteSubscriber extends RouteSubscriberBase {

  /**
   * {@inheritdoc}
   */
  protected function alterRoutes(RouteCollection $collection) {

    // Disable access to field UI for Sitewide Alerts.
    // Currently adding and configuring fields has little effect.
    $sitewideAlertFieldUiRoutesNames = [
      'entity.field_config.sitewide_alert_field_edit_form',
      'entity.field_config.sitewide_alert_storage_edit_form',
      'entity.field_config.sitewide_alert_storage_edit_form',
      'entity.sitewide_alert.field_ui_fields',
      'field_ui.field_storage_config_add_sitewide_alert',
      'entity.entity_form_display.sitewide_alert.default',
      'entity.entity_form_display.sitewide_alert.form_mode',
      'entity.entity_view_display.sitewide_alert.default',
      'entity.entity_view_display.sitewide_alert.view_mode',
    ];
    foreach ($sitewideAlertFieldUiRoutesNames as $routeName) {
      if ($route = $collection
        ->get($routeName)) {
        $route
          ->setRequirement('_access', 'FALSE');
      }
    }
  }

  /**
   * {@inheritdoc}
   */
  public static function getSubscribedEvents() {
    $events = parent::getSubscribedEvents();
    $events[RoutingEvents::ALTER] = [
      'onAlterRoutes',
      -101,
    ];
    return $events;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
RouteSubscriber::alterRoutes protected function Alters existing routes for a specific collection. Overrides RouteSubscriberBase::alterRoutes
RouteSubscriber::getSubscribedEvents public static function Returns an array of event names this subscriber wants to listen to. Overrides RouteSubscriberBase::getSubscribedEvents
RouteSubscriberBase::onAlterRoutes public function Delegates the route altering to self::alterRoutes(). 1