You are here

class RouteSubscriber in Salesforce Suite 8.4

Same name and namespace in other branches
  1. 5.0.x modules/salesforce_mapping_ui/src/Routing/RouteSubscriber.php \Drupal\salesforce_mapping_ui\Routing\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'
salesforce_mapping_ui.services.yml in modules/salesforce_mapping_ui/salesforce_mapping_ui.services.yml
modules/salesforce_mapping_ui/salesforce_mapping_ui.services.yml
1 service uses RouteSubscriber
salesforce_mapping.route_subscriber in modules/salesforce_mapping_ui/salesforce_mapping_ui.services.yml
Drupal\salesforce_mapping_ui\Routing\RouteSubscriber

File

modules/salesforce_mapping_ui/src/Routing/RouteSubscriber.php, line 14

Namespace

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

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

  /**
   * The mappable entity types service.
   *
   * @var \Drupal\salesforce_mapping\SalesforceMappableEntityTypesInterface
   */
  protected $mappable;

  /**
   * Constructs a new RouteSubscriber object.
   *
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_manager
   *   The entity type manager.
   */
  public function __construct(EntityTypeManagerInterface $entity_manager) {
    $this->entityTypeManager = $entity_manager;
  }

  /**
   * {@inheritdoc}
   */
  protected function alterRoutes(RouteCollection $collection) {
    foreach ($this->entityTypeManager
      ->getDefinitions() as $entity_type_id => $entity_type) {

      // If the entity didn't get a salesforce link template added by
      // hook_entity_types_alter(), skip it.
      if (!($path = $entity_type
        ->getLinkTemplate('salesforce'))) {
        continue;
      }

      // Create the "listing" route to show all the mapped objects for this
      // entity.
      $route = new Route($path);
      $route
        ->addDefaults([
        '_controller' => "\\Drupal\\salesforce_mapping_ui\\Controller\\MappedObjectController::listing",
        '_title' => "Salesforce mapped objects",
      ])
        ->addRequirements([
        '_custom_access' => '\\Drupal\\salesforce_mapping_ui\\Controller\\MappedObjectController::access',
      ])
        ->setOption('_admin_route', TRUE)
        ->setOption('_salesforce_entity_type_id', $entity_type_id)
        ->setOption('parameters', [
        $entity_type_id => [
          'type' => 'entity:' . $entity_type_id,
        ],
      ]);
      $collection
        ->add("entity.{$entity_type_id}.salesforce", $route);
    }
  }

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

}

Members

Namesort descending Modifiers Type Description Overrides
RouteSubscriber::$entityTypeManager protected property The entity type manager service.
RouteSubscriber::$mappable protected property The mappable entity types service.
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
RouteSubscriber::__construct public function Constructs a new RouteSubscriber object.
RouteSubscriberBase::onAlterRoutes public function Delegates the route altering to self::alterRoutes(). 1