class GroupContentListBuilder in Group 8
Same name and namespace in other branches
- 2.0.x src/Entity/Controller/GroupContentListBuilder.php \Drupal\group\Entity\Controller\GroupContentListBuilder
Provides a list controller for group content entities.
Hierarchy
- class \Drupal\Core\Entity\EntityHandlerBase uses DependencySerializationTrait, StringTranslationTrait
- class \Drupal\Core\Entity\EntityListBuilder implements EntityHandlerInterface, EntityListBuilderInterface uses MessengerTrait, RedirectDestinationTrait
- class \Drupal\group\Entity\Controller\GroupContentListBuilder
- class \Drupal\Core\Entity\EntityListBuilder implements EntityHandlerInterface, EntityListBuilderInterface uses MessengerTrait, RedirectDestinationTrait
Expanded class hierarchy of GroupContentListBuilder
File
- src/
Entity/ Controller/ GroupContentListBuilder.php, line 18
Namespace
Drupal\group\Entity\ControllerView source
class GroupContentListBuilder extends EntityListBuilder {
/**
* The group to show the content for.
*
* @var \Drupal\group\Entity\GroupInterface
*/
protected $group;
/**
* The entity type manager.
*
* @var \Drupal\Core\Routing\RedirectDestinationInterface
*/
protected $entityTypeManager;
/**
* The redirect destination.
*
* @var \Drupal\Core\Routing\RedirectDestinationInterface
*/
protected $redirectDestination;
/**
* Constructs a new GroupContentListBuilder object.
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
* @param \Drupal\Core\Routing\RedirectDestinationInterface $redirect_destination
* The redirect destination.
* @param \Drupal\Core\Routing\RouteMatchInterface $route_match
* The route match.
* @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
* The entity type definition.
*/
public function __construct(EntityTypeManagerInterface $entity_type_manager, RedirectDestinationInterface $redirect_destination, RouteMatchInterface $route_match, EntityTypeInterface $entity_type) {
parent::__construct($entity_type, $entity_type_manager
->getStorage($entity_type
->id()));
$this->entityTypeManager = $entity_type_manager;
$this->redirectDestination = $redirect_destination;
// There should always be a group on the route for group content lists.
$this->group = $route_match
->getParameters()
->get('group');
}
/**
* {@inheritdoc}
*/
public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) {
return new static($container
->get('entity_type.manager'), $container
->get('redirect.destination'), $container
->get('current_route_match'), $entity_type);
}
/**
* {@inheritdoc}
*/
protected function getEntityIds() {
$query = $this
->getStorage()
->getQuery();
$query
->sort($this->entityType
->getKey('id'));
// Only show group content for the group on the route.
$query
->condition('gid', $this->group
->id());
// Only add the pager if a limit is specified.
if ($this->limit) {
$query
->pager($this->limit);
}
return $query
->execute();
}
/**
* {@inheritdoc}
*/
public function buildHeader() {
$header = [
'id' => $this
->t('ID'),
'label' => $this
->t('Content label'),
'entity_type' => $this
->t('Entity type'),
'plugin' => $this
->t('Plugin used'),
];
return $header + parent::buildHeader();
}
/**
* {@inheritdoc}
*/
public function buildRow(EntityInterface $entity) {
/** @var \Drupal\group\Entity\GroupContentInterface $entity */
$row['id'] = $entity
->id();
// EntityListBuilder sets the table rows using the #rows property, so we
// need to add links as render arrays using the 'data' key.
$row['label']['data'] = $entity
->toLink()
->toRenderable();
$entity_type_id = $entity
->getContentPlugin()
->getEntityTypeId();
$row['entity_type'] = $this->entityTypeManager
->getDefinition($entity_type_id)
->getLabel();
$row['plugin'] = $entity
->getContentPlugin()
->getLabel();
return $row + parent::buildRow($entity);
}
/**
* {@inheritdoc}
*/
public function render() {
$build = parent::render();
$build['table']['#empty'] = $this
->t('There are no entities related to this group yet.');
return $build;
}
/**
* {@inheritdoc}
*/
protected function getDefaultOperations(EntityInterface $entity) {
/** @var \Drupal\group\Entity\GroupContentInterface $entity */
$operations = parent::getDefaultOperations($entity);
// Improve the edit and delete operation labels.
if (isset($operations['edit'])) {
$operations['edit']['title'] = $this
->t('Edit relation');
}
if (isset($operations['delete'])) {
$operations['delete']['title'] = $this
->t('Delete relation');
}
// Slap on redirect destinations for the administrative operations.
$destination = $this->redirectDestination
->getAsArray();
foreach ($operations as $key => $operation) {
$operations[$key]['query'] = $destination;
}
// Add an operation to view the actual entity.
if ($entity
->getEntity()
->access('view') && $entity
->getEntity()
->hasLinkTemplate('canonical')) {
$operations['view'] = [
'title' => $this
->t('View entity'),
'weight' => 101,
'url' => $entity
->getEntity()
->toUrl('canonical'),
];
}
return $operations;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
EntityHandlerBase:: |
protected | property | The module handler to invoke hooks on. | 2 |
EntityHandlerBase:: |
protected | function | Gets the module handler. | 2 |
EntityHandlerBase:: |
public | function | Sets the module handler for this handler. | |
EntityListBuilder:: |
protected | property | Information about the entity type. | |
EntityListBuilder:: |
protected | property | The entity type ID. | |
EntityListBuilder:: |
protected | property | The number of entities to list per page, or FALSE to list all entities. | 3 |
EntityListBuilder:: |
protected | property | The entity storage class. | 1 |
EntityListBuilder:: |
public | function | Builds a renderable list of operation links for the entity. | 2 |
EntityListBuilder:: |
protected | function | Ensures that a destination is present on the given URL. | |
EntityListBuilder:: |
protected | function | Gets the label of an entity. | |
EntityListBuilder:: |
public | function |
Provides an array of information to build a list of operation links. Overrides EntityListBuilderInterface:: |
2 |
EntityListBuilder:: |
public | function |
Gets the entity storage. Overrides EntityListBuilderInterface:: |
|
EntityListBuilder:: |
protected | function | Gets the title of the page. | 1 |
EntityListBuilder:: |
public | function |
Loads entities of this type from storage for listing. Overrides EntityListBuilderInterface:: |
4 |
GroupContentListBuilder:: |
protected | property | The entity type manager. | |
GroupContentListBuilder:: |
protected | property | The group to show the content for. | |
GroupContentListBuilder:: |
protected | property |
The redirect destination. Overrides RedirectDestinationTrait:: |
|
GroupContentListBuilder:: |
public | function |
Builds the header row for the entity listing. Overrides EntityListBuilder:: |
|
GroupContentListBuilder:: |
public | function |
Builds a row for an entity in the entity listing. Overrides EntityListBuilder:: |
|
GroupContentListBuilder:: |
public static | function |
Instantiates a new instance of this entity handler. Overrides EntityListBuilder:: |
|
GroupContentListBuilder:: |
protected | function |
Gets this list's default operations. Overrides EntityListBuilder:: |
|
GroupContentListBuilder:: |
protected | function |
Loads entity IDs using a pager sorted by the entity id. Overrides EntityListBuilder:: |
|
GroupContentListBuilder:: |
public | function |
Builds the entity listing as renderable array for table.html.twig. Overrides EntityListBuilder:: |
|
GroupContentListBuilder:: |
public | function |
Constructs a new GroupContentListBuilder object. Overrides EntityListBuilder:: |
|
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
RedirectDestinationTrait:: |
protected | function | Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url. | |
RedirectDestinationTrait:: |
protected | function | Returns the redirect destination service. | |
RedirectDestinationTrait:: |
public | function | Sets the redirect destination service. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |