GroupListBuilder.php in RNG - Events and Registrations 8
File
src/Lists/GroupListBuilder.php
View source
<?php
namespace Drupal\rng\Lists;
use Drupal\Core\Entity\EntityListBuilder;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Mail\MailFormatHelper;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\rng\EventManagerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class GroupListBuilder extends EntityListBuilder {
protected $eventManager;
protected $event;
public function __construct(EntityTypeInterface $entity_type, EntityStorageInterface $storage, EventManagerInterface $event_manager) {
parent::__construct($entity_type, $storage);
$this->eventManager = $event_manager;
}
public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) {
return new static($entity_type, $container
->get('entity.manager')
->getStorage($entity_type
->id()), $container
->get('rng.event_manager'));
}
public function render(EntityInterface $rng_event = NULL) {
if (isset($rng_event)) {
$this->event = $rng_event;
}
$render = parent::render();
$render['description'] = [
'#prefix' => '<p>',
'#markup' => $this
->t('Groups allow you to organize registrations. Some pre-made groups are automatically applied to registrations.'),
'#suffix' => '</p>',
'#weight' => -50,
];
$render['table']['#empty'] = t('No groups found for this event.');
return $render;
}
public function load() {
if (isset($this->event)) {
return $this->eventManager
->getMeta($this->event)
->getGroups();
}
return parent::load();
}
public function buildHeader() {
$header['label'] = t('Label');
$header['source'] = t('Source');
$header['description'] = t('Description');
return $header + parent::buildHeader();
}
public function buildRow(EntityInterface $entity) {
$row['label'] = $entity
->label();
$row['source'] = $entity
->isUserGenerated() ? t('User') : t('System');
$row['description'] = MailFormatHelper::htmlToText($entity
->getDescription());
return $row + parent::buildRow($entity);
}
}