You are here

public function EmptyPageController::emptyPageList in Empty Page 8

List out the pages created via empty page.

1 string reference to 'EmptyPageController::emptyPageList'
empty_page.routing.yml in ./empty_page.routing.yml
empty_page.routing.yml

File

src/Controller/EmptyPageController.php, line 16

Class

EmptyPageController
Manage empty pages.

Namespace

Drupal\empty_page\Controller

Code

public function emptyPageList() {
  $header = [
    t('INTERNAL PATH'),
    [
      'data' => t('Operations'),
      'colspan' => 2,
    ],
  ];
  $rows = [];
  $callbacks = self::emptyPageGetCallbacks();
  if (!empty($callbacks)) {
    foreach ($callbacks as $cid => $callback) {
      $view_url = Url::fromRoute('empty_page.page_' . $cid);
      $edit_url = Url::fromRoute('empty_page.edit_callback', [
        'cid' => $cid,
      ]);
      $delete_url = Url::fromRoute('empty_page.delete_callback', [
        'cid' => $cid,
      ]);
      $title = $callback['page_title'] ?: t('No title');
      $row = [
        Link::fromTextAndUrl($title, $view_url),
        Link::fromTextAndUrl(t('Edit'), $edit_url),
        Link::fromTextAndUrl(t('Delete'), $delete_url),
      ];
      $rows[] = $row;
    }
  }
  $table = [
    '#type' => 'table',
    '#header' => $header,
    '#rows' => $rows,
    '#empty' => t('No callbacks exist yet.'),
  ];
  $build = [
    '#type' => 'details',
    '#title' => 'Manage',
    '#children' => $table,
    '#open' => TRUE,
  ];
  return $build;
}