crm_core-8.x-3.x-dev/modules/crm_core_activity/src/ActivityListBuilder.php
modules/crm_core_activity/src/ActivityListBuilder.php
<?php
namespace Drupal\crm_core_activity;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityListBuilder;
use Drupal\Core\Entity\EntityTypeInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Activity List Builder.
*/
class ActivityListBuilder extends EntityListBuilder {
/**
* {@inheritdoc}
*/
public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) {
return new static(
$entity_type,
$container->get('entity_type.manager')->getStorage($entity_type->id())
);
}
/**
* {@inheritdoc}
*/
public function buildHeader() {
$header = [];
$header['date'] = $this->t('Activity Date');
$header['title'] = $this->t('Title');
$header['type'] = $this->t('Activity type');
return $header + parent::buildHeader();
}
/**
* {@inheritdoc}
*/
public function buildRow(EntityInterface $entity) {
$row = [];
$row['date']['data'] = $entity->get('activity_date')->view([
'label' => 'hidden',
]);
$row['title']['data'] = [
'#type' => 'link',
'#title' => $entity->label(),
'#url' => $entity->toUrl(),
];
$row['type'] = $entity->get('type')->entity->label();
return $row + parent::buildRow($entity);
}
/**
* {@inheritdoc}
*/
public function render() {
$build = parent::render();
$build['table']['#empty'] = $this->t('There are no activities available.');
return $build;
}
}
