RouteSubscriber.php in Schema.org configuration tool (RDF UI) 8
File
src/Routing/RouteSubscriber.php
View source
<?php
namespace Drupal\rdfui\Routing;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Routing\RouteSubscriberBase;
use Drupal\Core\Routing\RoutingEvents;
use Symfony\Component\Routing\Route;
use Symfony\Component\Routing\RouteCollection;
class RouteSubscriber extends RouteSubscriberBase {
protected $manager;
public function __construct(EntityTypeManagerInterface $manager) {
$this->manager = $manager;
}
public static function getSubscribedEvents() {
$events = parent::getSubscribedEvents();
$events[RoutingEvents::ALTER] = array(
'onAlterRoutes',
-100,
);
return $events;
}
protected function alterRoutes(RouteCollection $collection) {
foreach ($this->manager
->getDefinitions() as $entity_type_id => $entity_type) {
if ($route_name = $entity_type
->get('field_ui_base_route')) {
if (!($entity_route = $collection
->get($route_name))) {
continue;
}
$path = $entity_route
->getPath();
$options = array();
if (($bundle_entity_type = $entity_type
->getBundleEntityType()) && $bundle_entity_type !== 'bundle') {
$options['parameters'][$bundle_entity_type] = array(
'type' => 'entity:' . $bundle_entity_type,
);
$options['_field_ui'] = TRUE;
}
$defaults = array(
'entity_type_id' => $entity_type_id,
);
if (strpos($path, '{bundle}') === FALSE) {
$defaults['bundle'] = !$entity_type
->hasKey('bundle') ? $entity_type_id : '';
}
$route = new Route("{$path}/fields/rdf", array(
'_form' => '\\Drupal\\rdfui\\Form\\FieldMappings',
'_title' => 'Manage fields RDF',
) + $defaults, array(
'_permission' => 'administer ' . $entity_type_id . ' fields',
), $options);
$collection
->add("entity.{$entity_type_id}.rdf_ui_fields", $route);
}
}
}
}