You are here

public function TaskListBuilder::render in General Data Protection Regulation 8

Same name and namespace in other branches
  1. 8.2 modules/gdpr_tasks/src/TaskListBuilder.php \Drupal\gdpr_tasks\TaskListBuilder::render()
  2. 3.0.x modules/gdpr_tasks/src/TaskListBuilder.php \Drupal\gdpr_tasks\TaskListBuilder::render()

Builds the entity listing as renderable array for table.html.twig.

@todo Add a link to add a new item to the #empty text.

Overrides EntityListBuilder::render

File

modules/gdpr_tasks/src/TaskListBuilder.php, line 109

Class

TaskListBuilder
Defines a class to build a listing of Task entities.

Namespace

Drupal\gdpr_tasks

Code

public function render() {
  $build['requested']['title'] = [
    '#type' => 'html_tag',
    '#tag' => 'h3',
    '#value' => 'Requested tasks',
  ];
  $build['requested']['table'] = [
    '#type' => 'table',
    '#header' => $this
      ->buildHeader(),
    '#rows' => [],
    '#empty' => $this
      ->t('There is no open @label yet.', [
      '@label' => $this->entityType
        ->getLabel(),
    ]),
    '#cache' => [
      'contexts' => $this->entityType
        ->getListCacheContexts(),
      'tags' => $this->entityType
        ->getListCacheTags(),
    ],
  ];
  $build['reviewing']['title'] = [
    '#type' => 'html_tag',
    '#tag' => 'h3',
    '#value' => 'In-review tasks',
  ];
  $build['reviewing']['table'] = [
    '#type' => 'table',
    '#header' => $this
      ->buildHeader(),
    '#rows' => [],
    '#empty' => $this
      ->t('There are no tasks to be reviewed yet.'),
    '#cache' => [
      'contexts' => $this->entityType
        ->getListCacheContexts(),
      'tags' => $this->entityType
        ->getListCacheTags(),
    ],
  ];
  $build['processed']['title'] = [
    '#type' => 'html_tag',
    '#tag' => 'h3',
    '#value' => 'Processed tasks',
  ];
  $build['processed']['table'] = [
    '#type' => 'table',
    '#header' => $this
      ->buildHeader(),
    '#rows' => [],
    '#empty' => $this
      ->t('There are no processed tasks yet.'),
    '#cache' => [
      'contexts' => $this->entityType
        ->getListCacheContexts(),
      'tags' => $this->entityType
        ->getListCacheTags(),
    ],
  ];
  $build['closed']['title'] = [
    '#type' => 'html_tag',
    '#tag' => 'h3',
    '#value' => 'Closed tasks',
  ];
  $build['closed']['table'] = [
    '#type' => 'table',
    '#header' => $this
      ->buildHeader(),
    '#rows' => [],
    '#empty' => $this
      ->t('There are no closed tasks yet.'),
    '#cache' => [
      'contexts' => $this->entityType
        ->getListCacheContexts(),
      'tags' => $this->entityType
        ->getListCacheTags(),
    ],
  ];

  /* @var $entity \Drupal\gdpr_tasks\Entity\Task */
  foreach ($this
    ->load() as $entity) {
    if ($row = $this
      ->buildRow($entity)) {
      $build[$entity->status->value]['table']['#rows'][$entity
        ->id()] = $row;
    }
  }

  // Only add the pager if a limit is specified.
  if ($this->limit) {
    $build['pager'] = [
      '#type' => 'pager',
    ];
  }
  return $build;
}