Skip to content

Commit 00f499d

Browse files
committed
Remove AdminRoutes event because imho additional admin routes should be defined in routing.yml fix the test
1 parent 275739f commit 00f499d

File tree

7 files changed

+16
-241
lines changed

7 files changed

+16
-241
lines changed

src/Controller/OgAdminMembersController.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,7 @@ public function membersList(RouteMatchInterface $route_match) {
7070
* the function will return the default add member form.
7171
*/
7272
public function addPage(RouteMatchInterface $route_match) {
73-
$entity_type_id = $route_match->getRouteObject()
74-
->getOption('_og_entity_type_id');
75-
76-
$group = $route_match->getParameter($entity_type_id);
73+
$group = $route_match->getParameter('group');
7774

7875
$membership_types = $this->entityTypeManager
7976
->getStorage('og_membership_type')

src/Controller/OgAdminRoutesController.php

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,6 @@
1717
*/
1818
class OgAdminRoutesController extends ControllerBase {
1919

20-
/**
21-
* The event dispatcher service.
22-
*
23-
* @var \Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher
24-
*/
25-
protected $eventDispatcher;
26-
2720
/**
2821
* The access manager service.
2922
*
@@ -39,8 +32,7 @@ class OgAdminRoutesController extends ControllerBase {
3932
* @param \Drupal\Core\Access\AccessManagerInterface $access_manager
4033
* The access manager service.
4134
*/
42-
public function __construct(ContainerAwareEventDispatcher $event_dispatcher, AccessManagerInterface $access_manager) {
43-
$this->eventDispatcher = $event_dispatcher;
35+
public function __construct(AccessManagerInterface $access_manager) {
4436
$this->accessManager = $access_manager;
4537
}
4638

@@ -49,7 +41,6 @@ public function __construct(ContainerAwareEventDispatcher $event_dispatcher, Acc
4941
*/
5042
public static function create(ContainerInterface $container) {
5143
return new static(
52-
$container->get('event_dispatcher'),
5344
$container->get('access_manager')
5445
);
5546
}
@@ -64,16 +55,14 @@ public static function create(ContainerInterface $container) {
6455
* List of available admin routes for the current group.
6556
*/
6657
public function overview(RouteMatchInterface $route_match) {
67-
$entity_type_id = $route_match->getRouteObject()->getOption('_og_entity_type_id');
68-
6958
/** @var \Drupal\Core\Entity\EntityInterface $group */
70-
$group = $route_match->getParameter($entity_type_id);
59+
$group = $route_match->getParameter('group');
7160

7261
// Get list from routes.
7362
$content = [];
7463

7564
$route_name = "og_admin.members";
76-
$parameters = ['entity_type_id' => $entity_type_id, 'group' => $group->id()];
65+
$parameters = ['entity_type_id' => $group->getEntityTypeId(), 'group' => $group->id()];
7766

7867
// We don't use Url::fromRoute() here for the access check, as it will
7968
// prevent us from unit testing this method.

src/Event/OgAdminRoutesEvent.php

Lines changed: 0 additions & 76 deletions
This file was deleted.

src/Event/OgAdminRoutesEventInterface.php

Lines changed: 0 additions & 49 deletions
This file was deleted.

src/EventSubscriber/OgEventSubscriber.php

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ public static function getSubscribedEvents() {
7373
['provideDefaultNodePermissions'],
7474
],
7575
DefaultRoleEventInterface::EVENT_NAME => [['provideDefaultRoles']],
76-
OgAdminRoutesEventInterface::EVENT_NAME => [['provideOgAdminRoutes']],
7776
];
7877
}
7978

@@ -342,16 +341,4 @@ protected function generateEntityOperationPermissionList($group_content_entity_t
342341
return $permissions;
343342
}
344343

345-
/**
346-
* Provide OG admin routes.
347-
*
348-
* @param \Drupal\og\Event\OgAdminRoutesEventInterface $event
349-
* The OG admin routes event object.
350-
*/
351-
public function provideOgAdminRoutes(OgAdminRoutesEventInterface $event) {
352-
$routes_info = $event->getRoutesInfo();
353-
354-
$event->setRoutesInfo($routes_info);
355-
}
356-
357344
}

src/Routing/RouteSubscriber.php

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -95,36 +95,10 @@ protected function alterRoutes(RouteCollection $collection) {
9595

9696
$collection->add($route_name, $route);
9797

98-
// Add the routes defined in the event subscribers.
99-
$this->createRoutesFromEventSubscribers($og_admin_path, $entity_type_id, $collection);
100-
10198
}
10299

103100
}
104101

105-
/**
106-
* Add all the OG admin items to the route collection.
107-
*
108-
* @param string $og_admin_path
109-
* The OG admin path.
110-
* @param string $entity_type_id
111-
* The entity type ID.
112-
* @param \Symfony\Component\Routing\RouteCollection $collection
113-
* The route collection object.
114-
*/
115-
protected function createRoutesFromEventSubscribers($og_admin_path, $entity_type_id, RouteCollection $collection) {
116-
$event = new OgAdminRoutesEvent();
117-
$this->eventDispatcher->dispatch(OgAdminRoutesEventInterface::EVENT_NAME, $event);
118-
119-
foreach ($event->getRoutes($entity_type_id) as $name => $route_info) {
120-
// Add the parent route.
121-
$parent_route_name = "entity.$entity_type_id.og_admin_routes.$name";
122-
$parent_path = $og_admin_path . '/' . $route_info['path'];
123-
124-
$this->addRoute($collection, $parent_route_name, $parent_path, $route_info);
125-
}
126-
}
127-
128102
/**
129103
* Helper method to add route to collection.
130104
*

tests/src/Unit/OgAdminRoutesControllerTest.php

Lines changed: 12 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -51,41 +51,20 @@ class OgAdminRoutesControllerTest extends UnitTestCase {
5151
*/
5252
protected $routeMatch;
5353

54-
/**
55-
* The event dispatcher service.
56-
*
57-
* @var \Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher|\Prophecy\Prophecy\ObjectProphecy
58-
*/
59-
protected $eventDispatcher;
60-
6154
/**
6255
* The group entity.
6356
*
6457
* @var \Drupal\Core\Entity\EntityInterface|\Prophecy\Prophecy\ObjectProphecy
6558
*/
6659
protected $group;
6760

68-
/**
69-
* The OG admin route event.
70-
*
71-
* @var \Drupal\og\Event\OgAdminRoutesEvent
72-
*/
73-
protected $event;
74-
7561
/**
7662
* The entity type ID of the group entity.
7763
*
7864
* @var string
7965
*/
8066
protected $entityTypeId;
8167

82-
/**
83-
* The routes info as returned from the event subscribers.
84-
*
85-
* @var array
86-
*/
87-
protected $routesInfo;
88-
8968
/**
9069
* The Url object.
9170
*
@@ -109,25 +88,11 @@ public function setUp() {
10988
$this->routeMatch = $this->prophesize(RouteMatchInterface::class);
11089

11190
$this->group = $this->prophesize(EntityInterface::class);
112-
$this->event = $this->prophesize(OgAdminRoutesEvent::class);
113-
$this->eventDispatcher = $this->prophesize(ContainerAwareEventDispatcher::class);
11491
$this->route = $this->prophesize(Route::class);
11592
$this->entityTypeId = $this->randomMachineName();
11693
$this->entityId = rand(20, 30);
11794
$this->url = $this->prophesize(Url::class);
11895

119-
$this->routesInfo = [
120-
$this->randomMachineName() => [
121-
'title' => $this->randomMachineName(),
122-
'description' => $this->randomMachineName(),
123-
],
124-
125-
$this->randomMachineName() => [
126-
'title' => $this->randomMachineName(),
127-
'description' => $this->randomMachineName(),
128-
],
129-
];
130-
13196
$this
13297
->routeMatch
13398
->getRouteObject()
@@ -142,7 +107,7 @@ public function setUp() {
142107

143108
$this
144109
->routeMatch
145-
->getParameter($parameter_name)
110+
->getParameter('group')
146111
->willReturn($this->group->reveal());
147112

148113
$this
@@ -155,18 +120,6 @@ public function setUp() {
155120
->id()
156121
->willReturn($this->entityId);
157122

158-
$this
159-
->eventDispatcher
160-
->dispatch(OgAdminRoutesEventInterface::EVENT_NAME, Argument::type(OgAdminRoutesEvent::class))
161-
->willReturn($this->event->reveal())
162-
->shouldBeCalled();
163-
164-
$this
165-
->event
166-
->getRoutes($this->entityTypeId)
167-
->willReturn($this->routesInfo)
168-
->shouldBeCalled();
169-
170123
// Set the container for the string translation service.
171124
$translation = $this->getStringTranslationStub();
172125
$container = new ContainerBuilder();
@@ -194,8 +147,8 @@ public function testRoutesWithAccess() {
194147
$result = $this->getRenderElementResult(TRUE);
195148

196149
foreach ($result['og_admin_routes']['#content'] as $key => $value) {
197-
$this->assertEquals($this->routesInfo[$key]['title'], $value['title']);
198-
$this->assertEquals($this->routesInfo[$key]['description'], $value['description']);
150+
$this->assertEquals('Members', $value['title']);
151+
$this->assertEquals('Manage members', $value['description']);
199152
}
200153

201154
}
@@ -210,16 +163,16 @@ public function testRoutesWithAccess() {
210163
* The render array.
211164
*/
212165
protected function getRenderElementResult($allow_access) {
213-
$parameters = [$this->entityTypeId => $this->entityId];
214-
foreach (array_keys($this->routesInfo) as $name) {
215-
$route_name = "entity.{$this->entityTypeId}.og_admin_routes.$name";
216-
$this
217-
->accessManager
218-
->checkNamedRoute($route_name, $parameters)
219-
->willReturn($allow_access);
220-
}
166+
$parameters = ['entity_type_id' => $this->entityTypeId, 'group' => $this->entityId];
167+
168+
$route_name = "og_admin.members";
169+
$this
170+
->accessManager
171+
->checkNamedRoute($route_name, $parameters)
172+
->willReturn($allow_access);
173+
221174

222-
$og_admin_routes_controller = new OgAdminRoutesController($this->eventDispatcher->reveal(), $this->accessManager->reveal());
175+
$og_admin_routes_controller = new OgAdminRoutesController($this->accessManager->reveal());
223176
return $og_admin_routes_controller->overview($this->routeMatch->reveal());
224177
}
225178

0 commit comments

Comments
 (0)