api-8.x-1.x-dev/src/ListBuilder/PhpDocumentationListBuilder.php
src/ListBuilder/PhpDocumentationListBuilder.php
<?php
namespace Drupal\api\ListBuilder;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityListBuilder;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Routing\RedirectDestinationInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Provides a list controller for the php documentation entity type.
*/
class PhpDocumentationListBuilder extends EntityListBuilder {
/**
* The redirect destination service.
*
* @var \Drupal\Core\Routing\RedirectDestinationInterface
*/
protected $redirectDestination;
/**
* Constructs a new PhpDocumentationListBuilder object.
*
* @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
* The entity type definition.
* @param \Drupal\Core\Entity\EntityStorageInterface $storage
* The entity storage class.
* @param \Drupal\Core\Routing\RedirectDestinationInterface $redirect_destination
* The redirect destination service.
*/
public function __construct(EntityTypeInterface $entity_type, EntityStorageInterface $storage, RedirectDestinationInterface $redirect_destination) {
parent::__construct($entity_type, $storage);
$this->redirectDestination = $redirect_destination;
}
/**
* {@inheritdoc}
*/
public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) {
return new static(
$entity_type,
$container->get('entity_type.manager')->getStorage($entity_type->id()),
$container->get('redirect.destination')
);
}
/**
* {@inheritdoc}
*/
public function render() {
$build['table'] = parent::render();
$total = $this->getStorage()
->getQuery()
->accessCheck(TRUE)
->count()
->execute();
$build['summary']['#markup'] = $this->t('Total php documentation entries: @total', ['@total' => $total]);
return $build;
}
/**
* Loads entity IDs using a pager sorted by the entity id.
*
* @return array
* An array of entity IDs.
*/
protected function getEntityIds() {
$query = $this->getStorage()
->getQuery()
->accessCheck(TRUE)
->sort('object_name');
// Only add the pager if a limit is specified.
if ($this->limit) {
$query->pager($this->limit);
}
return $query->execute();
}
/**
* {@inheritdoc}
*/
public function buildHeader() {
$header['object_name'] = $this->t('Object name');
return $header;
}
/**
* {@inheritdoc}
*/
public function buildRow(EntityInterface $entity) {
/** @var \Drupal\api\Interfaces\PhpDocumentationInterface $entity */
$row['object_name'] = $entity->getExternalLink();
return $row;
}
}
