You are here

public function SimplePopupBlocksController::manage in Simple Popup Blocks 8

Same name and namespace in other branches
  1. 8.2 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'
simple_popup_blocks.routing.yml in ./simple_popup_blocks.routing.yml
simple_popup_blocks.routing.yml

File

src/Controller/SimplePopupBlocksController.php, line 54

Class

SimplePopupBlocksController
Controller routines for manage page routes.

Namespace

Drupal\simple_popup_blocks\Controller

Code

public function manage() {
  $trigger_method = '';
  $header = [
    [
      'data' => $this
        ->t('S.No'),
    ],
    [
      'data' => $this
        ->t('Popup selector'),
    ],
    [
      'data' => $this
        ->t('Popup sourse'),
    ],
    [
      'data' => $this
        ->t('Layout'),
    ],
    [
      'data' => $this
        ->t('Triggering'),
    ],
    [
      'data' => $this
        ->t('Status'),
    ],
    [
      'data' => $this
        ->t('Edit'),
    ],
    [
      'data' => $this
        ->t('Delete'),
    ],
  ];
  $result = SimplePopupBlocksStorage::loadAll($this->database);
  $rows = [];
  $increment = 1;
  foreach ($result as $row) {
    $popup_src = $row->type == 1 ? 'Custom css' : 'Drupal blocks';
    $url = Url::fromRoute('simple_popup_blocks.edit', [
      'first' => $row->pid,
    ]);
    $edit = Link::fromTextAndUrl($this
      ->t('Edit'), $url);
    $edit = $edit
      ->toRenderable();
    $url = Url::fromRoute('simple_popup_blocks.delete', [
      'first' => $row->pid,
    ]);
    $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[$row->layout];
    $status = $row->status ? 'Active' : 'Inactive';
    switch ($row->trigger_method) {
      case '0':
        $trigger_method = 'Automatic';
        break;
      case '1':
        $trigger_method = 'Manual';
        break;
      case '2':
        $trigger_method = 'Browser/tab close';
        break;
    }
    $rows[] = [
      [
        'data' => $increment,
      ],
      [
        'data' => $row->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;
}