-
Notifications
You must be signed in to change notification settings - Fork 134
/
OgUiController.php
142 lines (127 loc) · 4.08 KB
/
OgUiController.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
<?php
namespace Drupal\og_ui\Controller;
use Drupal\Core\Controller\ControllerBase;
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;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/**
* The OG UI controller.
*/
class OgUiController extends ControllerBase {
/**
* The OG group manager.
*
* @var \Drupal\og\GroupTypeManager
*/
protected $groupTypeManager;
/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* The entity type bundle info service.
*
* @var \Drupal\Core\Entity\EntityTypeBundleInfoInterface
*/
protected $entityTypeBundleInfo;
/**
* Constructs a OgUiController object.
*
* @param \Drupal\og\GroupTypeManager $group_manager
* The OG group manager.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
* @param \Drupal\Core\Entity\EntityTypeBundleInfoInterface $entity_type_bundle_info
* The entity type bundle info service.
*/
public function __construct(GroupTypeManager $group_manager, EntityTypeManagerInterface $entity_type_manager, EntityTypeBundleInfoInterface $entity_type_bundle_info) {
$this->groupTypeManager = $group_manager;
$this->entityTypeManager = $entity_type_manager;
$this->entityTypeBundleInfo = $entity_type_bundle_info;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('og.group_type_manager'),
$container->get('entity_type.manager'),
$container->get('entity_type.bundle.info')
);
}
/**
* Returns the overview of OG roles and permissions.
*
* @param string $type
* The type of overview, either 'roles' or 'permissions'.
*
* @return array
* The overview as a render array.
*/
public function rolesPermissionsOverviewPage($type) {
$action = $type === 'roles' ? t('Edit roles') : t('Edit permissions');
$header = [t('Group type'), t('Operations')];
$rows = [];
$build = [];
foreach ($this->groupTypeManager->getAllGroupBundles() as $entity_type => $bundles) {
$definition = $this->entityTypeManager->getDefinition($entity_type);
$bundle_info = $this->entityTypeBundleInfo->getBundleInfo($entity_type);
foreach ($bundles as $bundle) {
$rows[] = [
[
'data' => $definition->getLabel() . ' - ' . $bundle_info[$bundle]['label'],
],
[
'data' => Link::createFromRoute($action, 'og_ui.' . $type . '_overview', [
'entity_type_id' => $entity_type,
'bundle' => $bundle,
]),
],
];
}
}
$build['roles_table'] = [
'#theme' => 'table',
'#header' => $header,
'#rows' => $rows,
'#empty' => $this->t('No group types available.'),
];
return $build;
}
/**
* Title callback for rolesPermissionsOverviewPage().
*
* @param string $type
* The type of overview, either 'roles' or 'permissions'.
*
* @return \Drupal\Core\StringTranslation\TranslatableMarkup
* Return the translated title.
*/
public function rolesPermissionsOverviewTitleCallback($type) {
return $this->t('OG @type overview', ['@type' => $type]);
}
/**
* Title callback for the roles overview page.
*
* @param string $entity_type
* The group entity type.
* @param string $bundle
* The group bundle.
*
* @return \Drupal\Core\StringTranslation\TranslatableMarkup
* The roles overview page title.
*/
public function rolesOverviewPageTitleCallback($entity_type, $bundle) {
return $this->t('OG @type - @bundle roles', [
'@type' => $this->entityTypeManager->getDefinition($entity_type)->getLabel(),
'@bundle' => $this->entityTypeBundleInfo->getBundleInfo($entity_type)[$bundle]['label'],
]);
}
}