You are here

public function ProtectedPagesController::protectedPagesList in Protected Pages 8

Generate the list of protected pages.

1 string reference to 'ProtectedPagesController::protectedPagesList'
protected_pages.routing.yml in ./protected_pages.routing.yml
protected_pages.routing.yml

File

src/Controller/ProtectedPagesController.php, line 57

Class

ProtectedPagesController
Controller for listing protected pages.

Namespace

Drupal\protected_pages\Controller

Code

public function protectedPagesList() {
  $content = [];
  $content['message'] = [
    '#markup' => $this
      ->t('List of password protected pages.'),
  ];
  $rows = [];
  $headers = [
    $this
      ->t('#'),
    $this
      ->t('Relative Path'),
    $this
      ->t('Operations'),
  ];
  $count = 1;
  $result = $this->protectedPagesStorage
    ->loadAllProtectedPages();
  foreach ($result as $page) {
    $operation_drop_button = [
      [
        '#type' => 'dropbutton',
        '#links' => [
          'edit-protected-page' => [
            'title' => $this
              ->t('Edit'),
            'url' => Url::fromUri('internal:/admin/config/system/protected_pages/' . $page->pid . '/edit'),
          ],
          'delete-protected-page' => [
            'title' => $this
              ->t('Remove Password'),
            'url' => Url::fromUri('internal:/admin/config/system/protected_pages/' . $page->pid . '/delete'),
          ],
          'send-email' => [
            'title' => $this
              ->t('Send E-mail'),
            'url' => Url::fromUri('internal:/admin/config/system/protected_pages/' . $page->pid . '/send_email'),
          ],
        ],
      ],
    ];
    $operations = $this->renderer
      ->render($operation_drop_button);
    $rows[] = [
      'data' => [
        $count,
        Html::escape($page->path),
        $operations,
      ],
    ];
    $count++;
  }
  $content['table'] = [
    '#type' => 'table',
    '#header' => $headers,
    '#rows' => $rows,
    '#empty' => $this
      ->t('No records available.'),
  ];
  $content['pager'] = [
    '#type' => 'pager',
  ];
  return $content;
}