Skip to content
This repository has been archived by the owner on Feb 23, 2020. It is now read-only.

Commit

Permalink
Added RNG Debug sub-module.
Browse files Browse the repository at this point in the history
Added 'debug rng' permission.
Moved rules list to rng_debug.
Rules list now requires 'debug rng' permission.
Fixed #5
  • Loading branch information
dpi committed May 27, 2015
1 parent 136a0a2 commit ba59745
Show file tree
Hide file tree
Showing 9 changed files with 174 additions and 24 deletions.
7 changes: 7 additions & 0 deletions rng_debug/rng_debug.info.yml
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
3 changes: 3 additions & 0 deletions rng_debug/rng_debug.links.task.yml
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
3 changes: 3 additions & 0 deletions rng_debug/rng_debug.permissions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
debug rng:
title: 'Debug RNG'
description: 'Debug event settings.'
6 changes: 6 additions & 0 deletions rng_debug/rng_debug.services.yml
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 }
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,20 @@

/**
* @file
* Contains \Drupal\rng\Controller\RuleController.
* Contains \Drupal\rng_debug\Controller\DebugController.
*/

namespace Drupal\rng\Controller;
namespace Drupal\rng_debug\Controller;

use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Drupal\Core\Routing\RouteMatchInterface;

/**
* Controller for RNG rules.
* Controller for rng_debug.
*/
class RuleController extends ControllerBase implements ContainerInjectionInterface {
class DebugController extends ControllerBase implements ContainerInjectionInterface {

/**
* Provides a list of rng rules for an event.
*
Expand Down
78 changes: 78 additions & 0 deletions rng_debug/src/Plugin/Derivative/LocalTasks.php
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);
}

}
72 changes: 72 additions & 0 deletions rng_debug/src/Routing/RouteSubscriber.php
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);
}
}
}

}
7 changes: 0 additions & 7 deletions src/Plugin/Derivative/RNGLocalTasks.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,6 @@ public function getDerivativeDefinitions($base_plugin_definition) {
'weight' => 20,
);

$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,
);

$this->derivatives["rng.event.$entity_type.event.messages"] = array(
'title' => t('Messages'),
'route_name' => "rng.event.$entity_type.messages",
Expand Down
13 changes: 0 additions & 13 deletions src/Routing/RNGRouteSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,19 +90,6 @@ protected function alterRoutes(RouteCollection $collection) {
);
$collection->add("rng.event.$entity_type.access.reset", $route);

// Rules.
$route = new Route(
$canonical_path . '/event/rules',
array(
'_controller' => '\Drupal\rng\Controller\RuleController::listing',
'_title' => 'Rules',
'event' => $entity_type,
),
$manage_requirements,
$options
);
$collection->add("rng.event.$entity_type.rules", $route);

// Messages.
$route = new Route(
$canonical_path . '/event/messages',
Expand Down

0 comments on commit ba59745

Please sign in to comment.