RelationListBuilder.php in CRM Core 8.3
File
modules/crm_core_user_sync/src/RelationListBuilder.php
View source
<?php
namespace Drupal\crm_core_user_sync;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityListBuilder;
use Drupal\Core\Datetime\DateFormatterInterface;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Routing\RedirectDestinationInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class RelationListBuilder extends EntityListBuilder {
protected $dateFormatter;
protected $redirectDestination;
public function __construct(EntityTypeInterface $entity_type, EntityStorageInterface $storage, DateFormatterInterface $date_formatter, RedirectDestinationInterface $redirect_destination) {
parent::__construct($entity_type, $storage);
$this->dateFormatter = $date_formatter;
$this->redirectDestination = $redirect_destination;
}
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('date.formatter'), $container
->get('redirect.destination'));
}
public function render() {
$total = \Drupal::database()
->query('SELECT COUNT(*) FROM {crm_core_user_sync_relation}')
->fetchField();
$build['summary']['#markup'] = $this
->t('Total relations: @total', [
'@total' => $total,
]);
$build['table'] = parent::render();
return $build;
}
public function buildHeader() {
$header['id'] = $this
->t('ID');
$header['user'] = $this
->t('User');
$header['individual'] = $this
->t('Individual');
return $header + parent::buildHeader();
}
public function buildRow(EntityInterface $entity) {
$row['id'] = $entity
->id();
$row['user'] = $entity
->getUser()
->label();
$row['individual'] = $entity
->getIndividual()
->label();
return $row + parent::buildRow($entity);
}
protected function getDefaultOperations(EntityInterface $entity) {
$operations = parent::getDefaultOperations($entity);
$destination = $this->redirectDestination
->getAsArray();
foreach ($operations as $key => $operation) {
$operations[$key]['query'] = $destination;
}
return $operations;
}
}