public function SimplePopupBlocksController::manage in Simple Popup Blocks 8.2
Same name and namespace in other branches
- 8 src/Controller/SimplePopupBlocksController.php \Drupal\simple_popup_blocks\Controller\SimplePopupBlocksController::manage()
Manage page controller method to list the data.
1 string reference to 'SimplePopupBlocksController::manage'
File
- src/
Controller/ SimplePopupBlocksController.php, line 53
Class
- SimplePopupBlocksController
- Controller routines for manage page routes.
Namespace
Drupal\simple_popup_blocks\ControllerCode
public function manage() {
$trigger_method = '';
$header = [
[
'data' => $this
->t('S.No'),
],
[
'data' => $this
->t('Popup selector'),
],
[
'data' => $this
->t('Popup source'),
],
[
'data' => $this
->t('Layout'),
],
[
'data' => $this
->t('Triggering'),
],
[
'data' => $this
->t('Status'),
],
[
'data' => $this
->t('Edit'),
],
[
'data' => $this
->t('Delete'),
],
];
$configFactory = \Drupal::service('config.factory');
$configs = $configFactory
->listAll('simple_popup_blocks');
$rows = [];
$increment = 1;
foreach ($configs as $config) {
$data = $configFactory
->get($config);
if ($data
->get('uid') == null) {
continue;
}
$popup_src = $data
->get('type') == 1 ? 'Custom css' : 'Drupal blocks';
$url = Url::fromRoute('simple_popup_blocks.edit', [
'uid' => $data
->get('uid'),
]);
$edit = Link::fromTextAndUrl($this
->t('Edit'), $url);
$edit = $edit
->toRenderable();
$url = Url::fromRoute('simple_popup_blocks.delete', [
'uid' => $data
->get('uid'),
]);
$delete = Link::fromTextAndUrl($this
->t('Delete'), $url);
$delete = $delete
->toRenderable();
$layouts = [
0 => $this
->t('Top left'),
1 => $this
->t('Top Right'),
2 => $this
->t('Bottom left'),
3 => $this
->t('Bottom Right'),
4 => $this
->t('Center'),
5 => $this
->t('Top center'),
6 => $this
->t('Top bar'),
7 => $this
->t('Bottom bar'),
8 => $this
->t('Left bar'),
9 => $this
->t('Right bar'),
];
$layout = $layouts[$data
->get('layout')];
$status = $data
->get('status') ? 'Active' : 'Inactive';
switch ($data
->get('trigger_method')) {
case '0':
$trigger_method = 'Automatic';
break;
case '1':
$trigger_method = 'Manual';
break;
case '2':
$trigger_method = 'Browser/tab close';
break;
}
$rows[] = [
[
'data' => $data
->get('uid'),
],
[
'data' => $data
->get('identifier'),
],
[
'data' => $popup_src,
],
[
'data' => $layout,
],
[
'data' => $trigger_method,
],
[
'data' => $status,
],
[
'data' => $edit,
],
[
'data' => $delete,
],
];
$increment++;
}
$build['table'] = [
'#theme' => 'table',
'#header' => $header,
'#rows' => $rows,
'#empty' => 'No popup settings available.',
];
return $build;
}