OgUiController.php in Organic groups 8
File
og_ui/src/Controller/OgUiController.php
View source
<?php
declare (strict_types=1);
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\og\GroupTypeManagerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class OgUiController extends ControllerBase {
protected $groupTypeManager;
protected $entityTypeManager;
protected $entityTypeBundleInfo;
public function __construct(GroupTypeManagerInterface $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;
}
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'));
}
public function rolesPermissionsOverviewPage($type) {
$action = $type === 'roles' ? $this
->t('Edit roles') : $this
->t('Edit permissions');
$header = [
$this
->t('Group type'),
$this
->t('Operations'),
];
$rows = [];
$build = [];
foreach ($this->groupTypeManager
->getGroupMap() 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 . '_form', [
'entity_type' => $entity_type,
'bundle' => $bundle,
]),
],
];
}
}
$build['roles_table'] = [
'#theme' => 'table',
'#header' => $header,
'#rows' => $rows,
'#empty' => $this
->t('No group types available.'),
];
return $build;
}
public function rolesPermissionsOverviewTitleCallback($type) {
return $this
->t('OG @type overview', [
'@type' => $type,
]);
}
}