Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 32 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
CrmCaseListBuilder | |
0.00% |
0 / 32 |
|
0.00% |
0 / 5 |
42 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
createInstance | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
render | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
2 | |||
buildHeader | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
2 | |||
buildRow | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
6 |
1 | <?php |
2 | |
3 | namespace Drupal\crm_case; |
4 | |
5 | use Drupal\Core\Datetime\DateFormatterInterface; |
6 | use Drupal\Core\Entity\EntityInterface; |
7 | use Drupal\Core\Entity\EntityListBuilder; |
8 | use Drupal\Core\Entity\EntityStorageInterface; |
9 | use Drupal\Core\Entity\EntityTypeInterface; |
10 | use Symfony\Component\DependencyInjection\ContainerInterface; |
11 | |
12 | /** |
13 | * Provides a list controller for the crm case entity type. |
14 | */ |
15 | class CrmCaseListBuilder extends EntityListBuilder { |
16 | |
17 | /** |
18 | * The date formatter service. |
19 | * |
20 | * @var \Drupal\Core\Datetime\DateFormatterInterface |
21 | */ |
22 | protected $dateFormatter; |
23 | |
24 | /** |
25 | * Constructs a new CrmCaseListBuilder object. |
26 | * |
27 | * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type |
28 | * The entity type definition. |
29 | * @param \Drupal\Core\Entity\EntityStorageInterface $storage |
30 | * The entity storage class. |
31 | * @param \Drupal\Core\Datetime\DateFormatterInterface $date_formatter |
32 | * The date formatter service. |
33 | */ |
34 | public function __construct(EntityTypeInterface $entity_type, EntityStorageInterface $storage, DateFormatterInterface $date_formatter) { |
35 | parent::__construct($entity_type, $storage); |
36 | $this->dateFormatter = $date_formatter; |
37 | } |
38 | |
39 | /** |
40 | * {@inheritdoc} |
41 | */ |
42 | final public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) { |
43 | return new self( |
44 | $entity_type, |
45 | $container->get('entity_type.manager')->getStorage($entity_type->id()), |
46 | $container->get('date.formatter') |
47 | ); |
48 | } |
49 | |
50 | /** |
51 | * {@inheritdoc} |
52 | */ |
53 | public function render() { |
54 | $build['table'] = parent::render(); |
55 | |
56 | $total = $this->getStorage() |
57 | ->getQuery() |
58 | ->accessCheck(FALSE) |
59 | ->count() |
60 | ->execute(); |
61 | |
62 | $build['summary']['#markup'] = $this->t('Total crm cases: @total', ['@total' => $total]); |
63 | return $build; |
64 | } |
65 | |
66 | /** |
67 | * {@inheritdoc} |
68 | */ |
69 | public function buildHeader() { |
70 | $header['id'] = $this->t('ID'); |
71 | $header['label'] = $this->t('Label'); |
72 | $header['status'] = $this->t('Status'); |
73 | $header['uid'] = $this->t('Author'); |
74 | $header['created'] = $this->t('Created'); |
75 | $header['changed'] = $this->t('Updated'); |
76 | return $header + parent::buildHeader(); |
77 | } |
78 | |
79 | /** |
80 | * {@inheritdoc} |
81 | */ |
82 | public function buildRow(EntityInterface $entity) { |
83 | /** @var \Drupal\crm_case\CrmCaseInterface $entity */ |
84 | $row['id'] = $entity->id(); |
85 | $row['label'] = $entity->toLink(); |
86 | $row['status'] = $entity->get('status')->value ? $this->t('Enabled') : $this->t('Disabled'); |
87 | $row['uid']['data'] = [ |
88 | '#theme' => 'username', |
89 | '#account' => $entity->getOwner(), |
90 | ]; |
91 | $row['created'] = $this->dateFormatter->format($entity->get('created')->value); |
92 | $row['changed'] = $this->dateFormatter->format($entity->getChangedTime()); |
93 | return $row + parent::buildRow($entity); |
94 | } |
95 | |
96 | } |