Newer
Older
<?php
/**
* @file
* Contains \Drupal\node\NodeTypeListBuilder.
*/
namespace Drupal\node;
use Drupal\Core\Config\Entity\ConfigEntityListBuilder;
Alex Pott
committed
use Drupal\Core\Entity\EntityTypeInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
catch
committed
use Drupal\Core\Entity\EntityStorageInterface;
Angie Byron
committed
use Drupal\Core\Routing\UrlGeneratorInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Component\Utility\Xss;
use Drupal\Component\Utility\String;
/**
* Defines a class to build a listing of node type entities.
*
* @see \Drupal\node\Entity\NodeType
*/
class NodeTypeListBuilder extends ConfigEntityListBuilder {
/**
* The url generator service.
*
Angie Byron
committed
* @var \Drupal\Core\Routing\UrlGeneratorInterface
*/
protected $urlGenerator;
/**
* Constructs a NodeTypeFormController object.
*
Alex Pott
committed
* @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
* The entity type definition.
catch
committed
* @param \Drupal\Core\Entity\EntityStorageInterface $storage
* The entity storage class.
Angie Byron
committed
* @param \Drupal\Core\Routing\UrlGeneratorInterface $url_generator
* The url generator service.
*/
catch
committed
public function __construct(EntityTypeInterface $entity_type, EntityStorageInterface $storage, UrlGeneratorInterface $url_generator) {
Alex Pott
committed
parent::__construct($entity_type, $storage);
$this->urlGenerator = $url_generator;
}
Alex Pott
committed
/**
* {@inheritdoc}
*/
Alex Pott
committed
public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) {
return new static(
Alex Pott
committed
$entity_type,
catch
committed
$container->get('entity.manager')->getStorage($entity_type->id()),
$container->get('url_generator')
);
}
/**
* {@inheritdoc}
*/
public function buildHeader() {
$header['title'] = t('Name');
$header['description'] = array(
'data' => t('Description'),
'class' => array(RESPONSIVE_PRIORITY_MEDIUM),
);
return $header + parent::buildHeader();
}
/**
* {@inheritdoc}
*/
public function buildRow(EntityInterface $entity) {
$row['title'] = array(
'data' => $this->getLabel($entity),
'class' => array('menu-label'),
);
$row['description'] = Xss::filterAdmin($entity->description);
return $row + parent::buildRow($entity);
}
/**
* {@inheritdoc}
*/
public function getOperations(EntityInterface $entity) {
$operations = parent::getOperations($entity);
Alex Pott
committed
// Place the edit operation after the operations added by field_ui.module
// which have the weights 15, 20, 25.
if (isset($operations['edit'])) {
$operations['edit']['weight'] = 30;
}
return $operations;
}
/**
* {@inheritdoc}
*/
public function render() {
$build = parent::render();
$build['#empty'] = t('No content types available. <a href="@link">Add content type</a>.', array(
'@link' => $this->urlGenerator->generateFromPath('admin/structure/types/add'),
));
return $build;
}
}