BlocktabsListBuilder.php in Block Tabs 8
Namespace
Drupal\blocktabsFile
src/BlocktabsListBuilder.phpView source
<?php
namespace Drupal\blocktabs;
use Drupal\Core\Config\Entity\ConfigEntityListBuilder;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Routing\UrlGeneratorInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Defines a class to build a listing of blocktabs entities.
*
* @see \Drupal\blocktabs\Entity\BlockTabs
*/
class BlocktabsListBuilder extends ConfigEntityListBuilder {
/**
* The URL generator.
*
* @var \Drupal\Core\Routing\UrlGeneratorInterface
*/
protected $urlGenerator;
/**
* Constructs a new BlocktabsListBuilder object.
*
* @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
* The entity type definition.
* @param \Drupal\Core\Entity\EntityStorageInterface $entity_storage
* The blocktabs entity storage class.
* @param \Drupal\Core\Routing\UrlGeneratorInterface $url_generator
* The URL generator.
*/
public function __construct(EntityTypeInterface $entity_type, EntityStorageInterface $entity_storage, UrlGeneratorInterface $url_generator) {
parent::__construct($entity_type, $entity_storage);
$this->urlGenerator = $url_generator;
}
/**
* {@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('url_generator'), $container
->get('string_translation'));
}
/**
* {@inheritdoc}
*/
public function buildHeader() {
$header['label'] = $this
->t('Blocktabs name');
return $header + parent::buildHeader();
}
/**
* {@inheritdoc}
*/
public function buildRow(EntityInterface $entity) {
$row['label'] = $entity
->label();
return $row + parent::buildRow($entity);
}
/**
* {@inheritdoc}
*/
public function getDefaultOperations(EntityInterface $entity) {
$operations = parent::getDefaultOperations($entity);
// Remove destination URL from the edit link to allow editing tabs.
if (isset($operations['edit'])) {
$operations['edit']['url'] = $entity
->toUrl('edit-form');
}
return $operations;
}
/**
* {@inheritdoc}
*/
public function render() {
$build = parent::render();
$build['#empty'] = $this
->t('There are currently no blocktabs. <a href=":url">Add a new one</a>.', [
':url' => $this->urlGenerator
->generateFromRoute('blocktabs.add'),
]);
return $build;
}
}
Classes
Name![]() |
Description |
---|---|
BlocktabsListBuilder | Defines a class to build a listing of blocktabs entities. |