-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #149 from amitaibu/207-cleanup
Add Group tab
- Loading branch information
Showing
22 changed files
with
1,683 additions
and
19 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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,2 @@ | ||
og.og_admin_routes: | ||
deriver: \Drupal\og\Plugin\Derivative\OgLocalTask |
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
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,33 @@ | ||
<?php | ||
|
||
namespace Drupal\og\Controller; | ||
|
||
use Drupal\Core\Controller\ControllerBase; | ||
use Drupal\Core\Routing\RouteMatchInterface; | ||
use Drupal\views\Views; | ||
|
||
/** | ||
* OgAdminMembersController class. | ||
*/ | ||
class OgAdminMembersController extends ControllerBase { | ||
|
||
/** | ||
* Display list of members that belong to the group. | ||
* | ||
* @param \Drupal\Core\Routing\RouteMatchInterface $route_match | ||
* The route match service. | ||
* | ||
* @return array | ||
* The members overview View. | ||
*/ | ||
public function membersList(RouteMatchInterface $route_match) { | ||
$parameter_name = $route_match->getRouteObject()->getOption('_og_entity_type_id'); | ||
|
||
/** @var \Drupal\Core\Entity\EntityInterface $group */ | ||
$group = $route_match->getParameter($parameter_name); | ||
|
||
$arguments = [$group->getEntityTypeId(), $group->id()]; | ||
return Views::getView('og_members_overview')->executeDisplay('default', $arguments); | ||
} | ||
|
||
} |
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,107 @@ | ||
<?php | ||
|
||
namespace Drupal\og\Controller; | ||
|
||
use Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher; | ||
use Drupal\Core\Access\AccessManagerInterface; | ||
use Drupal\Core\Controller\ControllerBase; | ||
use Drupal\Core\Routing\RouteMatchInterface; | ||
use Drupal\Core\Url; | ||
use Drupal\og\Event\OgAdminRoutesEvent; | ||
use Drupal\og\Event\OgAdminRoutesEventInterface; | ||
use Symfony\Component\DependencyInjection\ContainerInterface; | ||
|
||
/** | ||
* The OG admin routes controller. | ||
*/ | ||
class OgAdminRoutesController extends ControllerBase { | ||
|
||
/** | ||
* The event dispatcher service. | ||
* | ||
* @var \Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher | ||
*/ | ||
protected $eventDispatcher; | ||
|
||
/** | ||
* The access manager service. | ||
* | ||
* @var \Drupal\Core\Access\AccessManagerInterface | ||
*/ | ||
protected $accessManager; | ||
|
||
/** | ||
* Constructs an OgAdminController object. | ||
* | ||
* @param \Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher $event_dispatcher | ||
* The event dispatcher service. | ||
* @param \Drupal\Core\Access\AccessManagerInterface $access_manager | ||
* The access manager service. | ||
*/ | ||
public function __construct(ContainerAwareEventDispatcher $event_dispatcher, AccessManagerInterface $access_manager) { | ||
$this->eventDispatcher = $event_dispatcher; | ||
$this->accessManager = $access_manager; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public static function create(ContainerInterface $container) { | ||
return new static( | ||
$container->get('event_dispatcher'), | ||
$container->get('access_manager') | ||
); | ||
} | ||
|
||
/** | ||
* Show all the available admin routes. | ||
* | ||
* @param \Drupal\Core\Routing\RouteMatchInterface $route_match | ||
* The route match service. | ||
* | ||
* @return array | ||
* List of available admin routes for the current group. | ||
*/ | ||
public function overview(RouteMatchInterface $route_match) { | ||
$parameter_name = $route_match->getRouteObject()->getOption('_og_entity_type_id'); | ||
|
||
/** @var \Drupal\Core\Entity\EntityInterface $group */ | ||
$group = $route_match->getParameter($parameter_name); | ||
|
||
$entity_type_id = $group->getEntityTypeId(); | ||
|
||
// Get list from routes. | ||
$content = []; | ||
|
||
$event = new OgAdminRoutesEvent(); | ||
$event = $this->eventDispatcher->dispatch(OgAdminRoutesEventInterface::EVENT_NAME, $event); | ||
|
||
foreach ($event->getRoutes($entity_type_id) as $name => $info) { | ||
$route_name = "entity.$entity_type_id.og_admin_routes.$name"; | ||
$parameters = [$entity_type_id => $group->id()]; | ||
|
||
// We don't use Url::fromRoute() here for the access check, as it will | ||
// prevent us from unit testing this method. | ||
if (!$this->accessManager->checkNamedRoute($route_name, $parameters)) { | ||
// User doesn't have access to the route. | ||
continue; | ||
} | ||
|
||
$content[$name]['title'] = $info['title']; | ||
$content[$name]['description'] = $info['description']; | ||
$content[$name]['url'] = Url::fromRoute($route_name, $parameters); | ||
} | ||
|
||
if (!$content) { | ||
return ['#markup' => $this->t('You do not have any administrative items.')]; | ||
} | ||
|
||
return [ | ||
'og_admin_routes' => [ | ||
'#theme' => 'admin_block_content', | ||
'#content' => $content, | ||
], | ||
]; | ||
} | ||
|
||
} |
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,65 @@ | ||
<?php | ||
|
||
namespace Drupal\og\Event; | ||
|
||
use Symfony\Component\EventDispatcher\Event; | ||
|
||
/** | ||
* Event that is fired when OG admin routes are being compiled. | ||
*/ | ||
class OgAdminRoutesEvent extends Event implements OgAdminRoutesEventInterface { | ||
|
||
/** | ||
* The routes info array. | ||
* | ||
* @var array | ||
*/ | ||
protected $routesInfo = []; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function setRoutes(array $routes_info) { | ||
$this->routesInfo = $routes_info; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getRoutes($entity_type_id) { | ||
$routes_info = []; | ||
|
||
foreach ($this->routesInfo as $name => $route_info) { | ||
|
||
$routes_info[$name] = $route_info; | ||
|
||
// Add default values. | ||
$routes_info[$name] += [ | ||
'description' => '', | ||
|
||
'requirements' => [ | ||
'_og_user_access_group' => 'administer group', | ||
], | ||
|
||
'options' => [ | ||
'parameters' => [ | ||
$entity_type_id => ['type' => 'entity:' . $entity_type_id], | ||
], | ||
// The above parameters doesn't send the entity, | ||
// so we will have to use the Route matcher to extract it. | ||
'_og_entity_type_id' => $entity_type_id, | ||
'_admin_route' => TRUE, | ||
], | ||
|
||
// Move the title and controller under the "defaults" key. | ||
'defaults' => [ | ||
'_controller' => $route_info['controller'], | ||
'_title' => $route_info['title'], | ||
], | ||
]; | ||
} | ||
|
||
return $routes_info; | ||
} | ||
|
||
} |
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,41 @@ | ||
<?php | ||
|
||
namespace Drupal\og\Event; | ||
|
||
/** | ||
* Interface for OgAdminRoutesEvent classes. | ||
* | ||
* This event allows implementing modules to provide their own OG Admin routes | ||
* or alter existing definitions that are provided by other modules. | ||
*/ | ||
interface OgAdminRoutesEventInterface { | ||
|
||
/** | ||
* The event name. | ||
*/ | ||
const EVENT_NAME = 'og.og_admin_routes'; | ||
|
||
/** | ||
* Set routes info. | ||
* | ||
* Array with the routes to create with the following keys: | ||
* - title | ||
* - controller. | ||
* | ||
* @param array $routes_info | ||
* The routes info array. | ||
*/ | ||
public function setRoutes(array $routes_info); | ||
|
||
/** | ||
* Get routes. | ||
* | ||
* @param string $entity_type_id | ||
* The entity type ID. | ||
* | ||
* @return array | ||
* Array with the routes info. | ||
*/ | ||
public function getRoutes($entity_type_id); | ||
|
||
} |
Oops, something went wrong.