This repository has been archived by the owner on Feb 23, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added 'debug rng' permission. Moved rules list to rng_debug. Rules list now requires 'debug rng' permission. Fixed #5
- Loading branch information
Showing
9 changed files
with
174 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
name: RNG Debug | ||
type: module | ||
description: 'Debug event settings.' | ||
package: RNG | ||
core: 8.x | ||
dependencies: | ||
- rng |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
rng_debug.local_tasks: | ||
class: \Drupal\Core\Menu\LocalTaskDefault | ||
deriver: \Drupal\rng_debug\Plugin\Derivative\LocalTasks |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
debug rng: | ||
title: 'Debug RNG' | ||
description: 'Debug event settings.' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
services: | ||
rng_debug.route_subscriber: | ||
class: Drupal\rng_debug\Routing\RouteSubscriber | ||
arguments: ['@entity.manager'] | ||
tags: | ||
- { name: event_subscriber } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<?php | ||
|
||
/** | ||
* @file | ||
* Contains \Drupal\rng_debug\Plugin\Derivative\LocalTasks. | ||
*/ | ||
|
||
namespace Drupal\rng_debug\Plugin\Derivative; | ||
|
||
use Drupal\Component\Plugin\Derivative\DeriverBase; | ||
use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface; | ||
use Symfony\Component\DependencyInjection\ContainerInterface; | ||
use Drupal\Core\Routing\RouteProviderInterface; | ||
|
||
/** | ||
* Provides dynamic tasks. | ||
*/ | ||
class LocalTasks extends DeriverBase implements ContainerDeriverInterface { | ||
|
||
/** | ||
* The entity type manager. | ||
* | ||
* @var \Drupal\Core\Entity\EntityManagerInterface | ||
*/ | ||
protected $entityManager; | ||
|
||
/** | ||
* Constructs a RNGLocalTasks object. | ||
* | ||
* @param \Drupal\Core\Routing\RouteProviderInterface $route_provider | ||
* The route provider. | ||
*/ | ||
public function __construct(RouteProviderInterface $route_provider) { | ||
$this->routeProvider = $route_provider; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public static function create(ContainerInterface $container, $base_plugin_id) { | ||
return new static( | ||
$container->get('router.route_provider') | ||
); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getDerivativeDefinitions($base_plugin_definition) { | ||
$this->derivatives = array(); | ||
|
||
$entity_type_config = array(); | ||
foreach (entity_load_multiple('event_type_config') as $entity) { | ||
$entity_type_config[$entity->entity_type][$entity->bundle] = $entity; | ||
} | ||
|
||
foreach ($entity_type_config as $entity_type => $bundles) { | ||
// Only need one set of tasks task per entity type. | ||
if ($this->routeProvider->getRouteByName("entity.$entity_type.canonical")) { | ||
$event_default = "rng.event.$entity_type.event.default"; | ||
|
||
$this->derivatives["rng.event.$entity_type.event.rules"] = array( | ||
'title' => t('Rules'), | ||
'route_name' => "rng.event.$entity_type.rules", | ||
'parent_id' => 'rng.local_tasks:' . $event_default, | ||
'weight' => 20, | ||
); | ||
} | ||
} | ||
|
||
foreach ($this->derivatives as &$entry) { | ||
$entry += $base_plugin_definition; | ||
} | ||
|
||
return parent::getDerivativeDefinitions($base_plugin_definition); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?php | ||
|
||
/** | ||
* @file | ||
* Contains \Drupal\rng_debug\Routing\RouteSubscriber. | ||
*/ | ||
|
||
namespace Drupal\rng_debug\Routing; | ||
|
||
use Drupal\Core\Entity\EntityManagerInterface; | ||
use Drupal\Core\Routing\RouteSubscriberBase; | ||
use Symfony\Component\Routing\Route; | ||
use Symfony\Component\Routing\RouteCollection; | ||
|
||
/** | ||
* Dynamic routes. | ||
*/ | ||
class RouteSubscriber extends RouteSubscriberBase { | ||
|
||
/** | ||
* The entity type manager. | ||
* | ||
* @var \Drupal\Core\Entity\EntityManagerInterface | ||
*/ | ||
protected $entityManager; | ||
|
||
/** | ||
* Constructs a RouteSubscriber object. | ||
* | ||
* @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager | ||
* The entity manager. | ||
*/ | ||
public function __construct(EntityManagerInterface $entity_manager) { | ||
$this->entityManager = $entity_manager; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function alterRoutes(RouteCollection $collection) { | ||
$entity_type_config = array(); | ||
foreach (entity_load_multiple('event_type_config') as $entity) { | ||
$entity_type_config[$entity->entity_type] = $entity->entity_type; | ||
} | ||
|
||
foreach ($entity_type_config as $entity_type) { | ||
$definition = $this->entityManager->getDefinition($entity_type); | ||
if ($canonical_path = $definition->getLinkTemplate('canonical')) { | ||
$manage_requirements = [ | ||
'_entity_access' => $entity_type . '.manage event', | ||
'_permission' => 'debug rng', | ||
]; | ||
$options = []; | ||
$options['parameters'][$entity_type]['type'] = 'entity:' . $entity_type; | ||
|
||
// Rules. | ||
$route = new Route( | ||
$canonical_path . '/event/rules', | ||
array( | ||
'_controller' => '\Drupal\rng_debug\Controller\DebugController::listing', | ||
'_title' => 'Rules', | ||
'event' => $entity_type, | ||
), | ||
$manage_requirements, | ||
$options | ||
); | ||
$collection->add("rng.event.$entity_type.rules", $route); | ||
} | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters