class RouteSubscriber in Pardot Integration 2.x
Subscriber for Devel routes.
Hierarchy
- class \Drupal\Core\Routing\RouteSubscriberBase implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
- class \Drupal\pardot\Routing\RouteSubscriber
Expanded class hierarchy of RouteSubscriber
See also
\Drupal\devel\Controller\EntityDebugController
\Drupal\devel\Plugin\Derivative\DevelLocalTask
1 string reference to 'RouteSubscriber'
1 service uses RouteSubscriber
File
- src/
Routing/ RouteSubscriber.php, line 18
Namespace
Drupal\pardot\RoutingView source
class RouteSubscriber extends RouteSubscriberBase {
/**
* The entity type manager service.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* 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 ($entity_type_id === 'contact_form' || $entity_type_id === 'webform') {
if ($route = $this
->getFormRoute($entity_type)) {
$collection
->add("entity.{$entity_type_id}.pardot_form_mapping", $route);
}
}
}
return $collection;
}
/**
* Gets the version history route.
*
* @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
* The entity type.
*
* @return \Symfony\Component\Routing\Route|null
* The generated route, if available.
*/
protected function getFormRoute(EntityTypeInterface $entity_type) {
if ($route = new Route($entity_type
->getLinkTemplate('pardot-form-mapping'))) {
$entity_type_id = $entity_type
->id();
if ($entity_type_id === 'contact_form') {
$method = 'renderContactFormMapping';
}
if ($entity_type_id === 'webform') {
$method = 'renderWebformFormMapping';
}
if ($method) {
$route
->setDefaults([
// '_title' => "Pardot Form Map: @contact_form",
'_title' => "Pardot Form Map",
'_controller' => '\\Drupal\\pardot\\Controller\\PardotFormMappingController::' . $method,
])
->setRequirement('_permission', 'administer pardot form map')
->setOption('parameters', [
$entity_type_id => 'entity:' . $entity_type_id,
])
->setOption('_admin_route', TRUE);
return $route;
}
}
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
$events = parent::getSubscribedEvents();
$events[RoutingEvents::ALTER] = [
'onAlterRoutes',
100,
];
return $events;
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
RouteSubscriber:: |
protected | property | The entity type manager service. | |
RouteSubscriber:: |
protected | function |
Alters existing routes for a specific collection. Overrides RouteSubscriberBase:: |
|
RouteSubscriber:: |
protected | function | Gets the version history route. | |
RouteSubscriber:: |
public static | function |
Overrides RouteSubscriberBase:: |
|
RouteSubscriber:: |
public | function | Constructs a new RouteSubscriber object. | |
RouteSubscriberBase:: |
public | function | Delegates the route altering to self::alterRoutes(). | 1 |