Skip to content

Commit

Permalink
Tweak roles list operations
Browse files Browse the repository at this point in the history
  • Loading branch information
zerolab committed Apr 12, 2017
1 parent 2387dc0 commit c3118ce
Showing 1 changed file with 21 additions and 17 deletions.
38 changes: 21 additions & 17 deletions og_ui/src/Controller/OgUiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Drupal\Core\Entity\EntityTypeBundleInfoInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Link;
use Drupal\Core\Url;
use Drupal\og\Og;
use Drupal\og\GroupTypeManager;
use Symfony\Component\DependencyInjection\ContainerInterface;
Expand Down Expand Up @@ -147,44 +148,47 @@ public function rolesOverviewPage($entity_type = '', $bundle = '') {
foreach ($this->entityTypeManager->getStorage('og_role')->loadByProperties($properties) as $role) {
// Add the role name cell.
$columns = [['data' => $role->getLabel()]];
$operations = [];
$edit_permissions = [
'title' => $this->t('Edit permissions'),
'weight' => 10,
'url' => Url::fromRoute('og_ui.permissions_edit_form', [
'entity_type' => $entity_type,
'bundle' => $bundle,
'og_role' => $role->id(),
]),
];

// Add the edit role link if the role is editable.
if (!$role->isLocked()) {
$operations = [];
if ($role->access('update') && $role->hasLinkTemplate('edit-form')) {
$operations['edit'] = [
'title' => $this->t('Edit role'),
'weight' => 10,
'url' => $role->urlInfo('edit-form'),
];
}

$operations['permissions'] = $edit_permissions;
if ($role->access('delete') && $role->hasLinkTemplate('delete-form')) {
$operations['delete'] = [
'title' => $this->t('Delete role'),
'weight' => 100,
'url' => $role->urlInfo('delete-form'),
];
}

$columns[] = [
'data' => [
'#type' => 'operations',
'#links' => $operations,
],
];
}
else {
$columns[] = ['data' => $this->t('Locked')];
// Add the edit permissions link.
// @TODO investigate using a clean id string (id() is "node-bundle-rid").
$operations['permissions'] = $edit_permissions;
}

// Add the edit permissions link.
// @TODO investigate using a clean id string (id() is "node-bundle-rid")
$columns[] = [
'data' => Link::createFromRoute($this->t('Edit permissions'), 'og_ui.permissions_edit_form', [
'entity_type' => $entity_type,
'bundle' => $bundle,
'og_role' => $role->id(),
]),
'data' => [
'#type' => 'operations',
'#links' => $operations,
],
];

$rows[] = $columns;
Expand All @@ -194,7 +198,7 @@ public function rolesOverviewPage($entity_type = '', $bundle = '') {
'#theme' => 'table',
'#header' => [
$this->t('Role name'),
['data' => $this->t('Operations'), 'colspan' => 2],
['data' => $this->t('Operations')],
],
'#rows' => $rows,
'#empty' => $this->t('No roles available.'),
Expand Down

0 comments on commit c3118ce

Please sign in to comment.