IndividualListBuilder.php in CRM Core 8.2
File
modules/crm_core_contact/src/IndividualListBuilder.php
View source
<?php
namespace Drupal\crm_core_contact;
use Drupal\Core\Datetime\DateFormatter;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityListBuilder;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class IndividualListBuilder extends EntityListBuilder {
protected $dateFormatter;
public function __construct(EntityTypeInterface $entity_type, EntityStorageInterface $storage, DateFormatter $date_formatter) {
parent::__construct($entity_type, $storage);
$this->dateFormatter = $date_formatter;
}
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'));
}
public function buildHeader() {
$header = array();
$header['label'] = $this
->t('Label');
$header['type'] = array(
'data' => $this
->t('Individual type'),
'class' => array(
RESPONSIVE_PRIORITY_MEDIUM,
),
);
$header['changed'] = array(
'data' => $this
->t('Updated'),
'class' => array(
RESPONSIVE_PRIORITY_LOW,
),
);
return $header + parent::buildHeader();
}
public function buildRow(EntityInterface $entity) {
$row = array();
$row['label']['data'] = array(
'#type' => 'link',
'#title' => $entity
->label(),
'#url' => $entity
->urlInfo(),
);
$row['type'] = $entity
->get('type')->entity
->label();
$row['changed'] = $this->dateFormatter
->format($entity
->get('changed')->value, 'short');
return $row + parent::buildRow($entity);
}
public function render() {
$build = parent::render();
$build['table']['#empty'] = $this
->t('There are no individuals available. Add one now.');
return $build;
}
}