content_planner-8.x-1.x-dev/modules/content_kanban/src/KanbanLogListBuilder.php

modules/content_kanban/src/KanbanLogListBuilder.php
<?php

namespace Drupal\content_kanban;

use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityListBuilder;
use Drupal\Core\Link;

/**
 * Defines a class to build a listing of Kanban Log entities.
 *
 * @ingroup content_kanban
 */
class KanbanLogListBuilder extends EntityListBuilder {

  /**
   * Custom load of entities.
   *
   * @return \Drupal\Core\Entity\EntityInterface[]
   *   Returns an array with the entities.
   */
  public function load() {

    $query = \Drupal::entityQuery('content_kanban_log');
    $query->accessCheck();
    $query->sort('created', 'DESC');

    $result = $query->execute();
    return $this->storage->loadMultiple($result);
  }

  /**
   * {@inheritdoc}
   */
  public function buildHeader() {

    $header['id'] = $this->t('Kanban Log ID');
    $header['name'] = $this->t('Name');
    $header['workflow'] = $this->t('Workflow');
    $header['entity'] = $this->t('Entity / Entity ID');
    $header['state_from'] = $this->t('State from');
    $header['state_to'] = $this->t('State to');

    return $header + parent::buildHeader();
  }

  /**
   * {@inheritdoc}
   */
  public function buildRow(EntityInterface $entity) {

    /** @var \Drupal\content_kanban\Entity\KanbanLog $entity */

    $row['id'] = $entity->id();
    $row['name'] = $entity->label();

    // Workflow.
    if ($workflow = $entity->getWorkflow()) {
      $row['workflow'] = $workflow->label();
    }
    else {
      $row['workflow'] = $this->t('Workflow with ID @id does not exist anymore', ['@id' => $entity->getWorkflowId()]);
    }

    if ($logEntity = $entity->getEntityObject()) {
      $row['entity'] = new Link($logEntity->label(), $logEntity->toUrl());
    }
    else {
      $row['entity'] = $this->t('Entity @entity_type with ID @id does not exist anymore', [
        '@id' => $entity->getEntityId(),
        '@entity_type' => $entity->getType(),
      ]);
    }

    $row['state_from'] = $entity->getStateFrom();
    $row['state_to'] = $entity->getStateTo();

    return $row + parent::buildRow($entity);
  }

}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc