You are here

public function DraggableDashboardController::adminOverview in Draggable dashboard 8

Displays the draggable dashboard administration overview page.

Parameters

\Symfony\Component\HttpFoundation\Request $request: The request object.

Return value

array A render array as expected by drupal_render().

1 string reference to 'DraggableDashboardController::adminOverview'
draggable_dashboard.routing.yml in ./draggable_dashboard.routing.yml
draggable_dashboard.routing.yml

File

src/Controller/DraggableDashboardController.php, line 52

Class

DraggableDashboardController
Controller routines for draggable dashboards.

Namespace

Drupal\draggable_dashboard\Controller

Code

public function adminOverview(Request $request) {
  $rows = [];
  $storage = $this->entityTypeManager
    ->getStorage('dashboard_entity');
  $header = [
    $this
      ->t('Title'),
    $this
      ->t('Description'),
    $this
      ->t('Operations'),
  ];
  $dashboards = $storage
    ->getQuery()
    ->execute();
  foreach ($dashboards as $dashboardID) {
    $dashboard = $storage
      ->load($dashboardID);
    $row = [];
    $row[] = $dashboard
      ->get('title');
    $row[] = $dashboard
      ->get('description');
    $links = [
      'manage' => [
        'title' => $this
          ->t('Manage Blocks'),
        'url' => Url::fromRoute('draggable_dashboard.manage_dashboard', [
          'did' => $dashboard
            ->id(),
        ]),
      ],
      'edit' => [
        'title' => $this
          ->t('Edit'),
        'url' => Url::fromRoute('draggable_dashboard.edit_dashboard', [
          'did' => $dashboard
            ->id(),
        ]),
      ],
      'delete' => [
        'title' => $this
          ->t('Delete'),
        'url' => Url::fromRoute('draggable_dashboard.delete_dashboard', [
          'did' => $dashboard
            ->id(),
        ]),
      ],
    ];
    $row[] = [
      'data' => [
        '#type' => 'operations',
        '#links' => $links,
      ],
    ];
    $rows[] = $row;
  }
  $form['dashboard_table'] = [
    '#type' => 'table',
    '#header' => $header,
    '#rows' => $rows,
    '#empty' => $this
      ->t('No draggable dashboards available.'),
    '#weight' => 120,
  ];
  return $form;
}