You are here

protected function ChangesListController::adminOverview in Workspace 8

Returns an administrative overview of all changes.

Parameters

array $entities:

Return value

array A render array representing the administrative page content. A render array representing the administrative page content.

Throws

\Drupal\Core\Entity\EntityMalformedException

1 call to ChangesListController::adminOverview()
ChangesListController::viewChanges in src/Controller/ChangesListController.php
View a list of changes between current workspace and the target workspace.

File

src/Controller/ChangesListController.php, line 246

Class

ChangesListController

Namespace

Drupal\workspace\Controller

Code

protected function adminOverview(array $entities = []) {
  $total = count($entities);

  // Initialize the pager.
  $page = pager_default_initialize($total, $this->changesPerPage);

  // Split the items up into chunks:
  $chunks = array_chunk($entities, $this->changesPerPage);

  // Get changes for the current page:
  $current_page_changes = isset($chunks[$page]) ? $chunks[$page] : [];
  $headers = [
    $this
      ->t('Entities'),
    $this
      ->t('Entity type'),
    $this
      ->t('Status'),
    $this
      ->t('Author'),
    $this
      ->t('Changed time'),
    $this
      ->t('Operations'),
  ];
  $rows = [];

  /** @var \Drupal\Core\Entity\ContentEntityInterface[] $current_page_changes */
  foreach ($current_page_changes as $entity) {
    $row = [
      $entity
        ->label() ?: '* ' . $this
        ->t('No label') . ' *',
      $entity
        ->getEntityTypeId(),
    ];

    //Set status.
    if ($entity->_deleted->value) {
      $row[] = $this
        ->t('Deleted');
    }
    elseif (!empty($entity->_rev->value) && $entity->_rev->value[0] == 1) {
      $row[] = $this
        ->t('Added');
    }
    else {
      $row[] = $this
        ->t('Changed');
    }

    // Set the author.
    if (method_exists($entity, 'getOwner')) {
      $row[] = ($name = $entity
        ->getOwner()
        ->get('name')->value) ? $name : '* ' . $this
        ->t('No author') . ' *';
    }
    else {
      $row[] = '* ' . $this
        ->t('No author') . ' *';
    }

    // Set changed value.
    if (method_exists($entity, 'getChangedTime') && ($changed = $entity
      ->getChangedTime())) {
      $row[] = DateTimePlus::createFromTimestamp($changed)
        ->format('m/d/Y | H:i:s | e');
    }
    else {
      $row[] = '* ' . $this
        ->t('No changed time') . ' *';
    }

    // Set operations.
    $links = [];
    if ($entity
      ->hasLinkTemplate('canonical') && !$entity->_deleted->value) {
      $links['view'] = [
        'title' => t('View'),
        'url' => $entity
          ->toUrl('canonical', [
          'absolute' => TRUE,
        ]),
      ];
    }
    else {
      $links['view'] = [
        'title' => '* ' . $this
          ->t('No view link') . ' *',
      ];
    }
    $row[] = [
      'data' => [
        '#type' => 'operations',
        '#links' => $links,
      ],
    ];
    $rows[] = $row;
  }
  $build['prefix']['#markup'] = '<p>' . $this
    ->t('The array is sorted by last change first.') . '</p>';
  $build['changes-list'] = [
    '#type' => 'table',
    '#header' => $headers,
    '#rows' => $rows,
    '#empty' => t('There are no changes.'),
  ];
  $build['pager'] = [
    '#type' => 'pager',
  ];
  return $build;
}