View source
<?php
namespace Drupal\add_to_head\Controller;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Url;
use Drupal\Core\Link;
class AddToHeadController extends ControllerBase {
public function adminOverview() {
$settings = add_to_head_get_settings();
$add_profile_url = Url::fromRoute('add_to_head.add_profile');
$link = Link::fromTextAndUrl($this
->t('Add one now'), $add_profile_url)
->toRenderable();
$table = [
'#type' => 'table',
'#header' => [
$this
->t('Title'),
$this
->t('Paths'),
$this
->t('Roles'),
$this
->t('Scope'),
$this
->t('Operations'),
],
'#empty' => $this
->t('No profiles configured yet. @link.', array(
'@link' => \Drupal::service('renderer')
->render($link),
)),
];
$role_names = user_role_names();
foreach ($settings as $delta => $profile) {
$key = $profile['name'];
$path_list = [
'#theme' => 'item_list',
'#title' => \Drupal\Component\Utility\Unicode::ucfirst($profile['paths']['visibility']),
];
foreach (explode("\n", $profile['paths']['paths']) as $path) {
$path_list['#items'][] = [
'#plain_text' => $path,
];
}
$role_list = [
'#theme' => 'item_list',
'#title' => \Drupal\Component\Utility\Unicode::ucfirst($profile['roles']['visibility']),
'#items' => array_intersect_key($role_names, array_flip($profile['roles']['list'])),
];
$table[$key] = [
'name' => [
'#plain_text' => $profile['name'],
],
'paths' => $path_list,
'roles' => $role_list,
'scope' => [
'#plain_text' => \Drupal\Component\Utility\Unicode::ucfirst($profile['scope']),
],
];
if (TRUE) {
$params = [
'profile' => $profile['name'],
];
$table[$key]['ops'] = [
'#type' => 'operations',
'#links' => [
'edit' => [
'title' => $this
->t('Edit'),
'url' => Url::fromRoute('add_to_head.edit_profile', $params),
],
'delete' => [
'title' => $this
->t('Delete'),
'url' => Url::fromRoute('add_to_head.delete_profile', $params),
],
],
];
}
else {
$table[$key]['ops']['#plain_text'] = $this
->t('None (in code)');
}
}
return $table;
}
}