Skip to content

Commit 737a2cb

Browse files
committed
Sortable AMI sets
Had to break the Listing Cache (documented like nowhere) to allow our theme + Sorts to actually change the Table (if not the rendered version got stuck)
1 parent 536387e commit 737a2cb

File tree

2 files changed

+56
-15
lines changed

2 files changed

+56
-15
lines changed

src/Entity/Controller/amiSetEntityListBuilder.php

Lines changed: 55 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
use Drupal\Core\Entity\EntityInterface;
77
use Drupal\Core\Entity\EntityListBuilder;
88
use Drupal\ami\AmiUtilityService;
9+
use Drupal\Core\Entity\Query\QueryInterface;
910

10-
11-
/**
12-
* Provides a list controller for the Ami Set entity.
13-
*
14-
* @ingroup ami
15-
*/
11+
/**
12+
* Provides a list controller for the Ami Set entity.
13+
*
14+
* @ingroup ami
15+
*/
1616
class amiSetEntityListBuilder extends EntityListBuilder {
1717

1818
/**
@@ -44,10 +44,32 @@ public function render() {
4444
*/
4545
public function buildHeader() {
4646
$header['uuid'] = $this->t('Set UUID');
47-
$header['id'] = $this->t('Set ID');
48-
$header['name'] = $this->t('Name');
49-
$header['last update'] = $this->t('Last update');
50-
$header['status'] = $this->t('Status');
47+
$header['id'] = [
48+
'data' => $this->t('Set ID'),
49+
'class' => [RESPONSIVE_PRIORITY_LOW],
50+
'field' => 'id',
51+
'specifier' => 'id',
52+
'sort' => 'asc',
53+
];
54+
$header['name'] = [
55+
'data' => $this->t('Name'),
56+
'class' => [RESPONSIVE_PRIORITY_MEDIUM],
57+
'field' => 'name',
58+
'specifier' => 'name',
59+
];
60+
$header['changed'] = [
61+
'data' => $this->t('Last update'),
62+
'class' => [RESPONSIVE_PRIORITY_LOW],
63+
'field' => 'changed',
64+
'specifier' => 'changed',
65+
];
66+
$header['status'] = [
67+
'data' => $this->t('Status'),
68+
'class' => [RESPONSIVE_PRIORITY_LOW],
69+
'field' => 'status',
70+
'specifier' => 'status',
71+
];
72+
5173
return $header + parent::buildHeader();
5274
}
5375

@@ -56,15 +78,33 @@ public function buildHeader() {
5678
*/
5779
public function buildRow(EntityInterface $entity) {
5880
/* @var $entity \Drupal\ami\Entity\amiSetEntity */
59-
$row['uuid'] = $entity->uuid();
60-
$row['id'] = $entity->id();
61-
$row['name'] = $entity->toLink();
62-
$row['last update'] = \Drupal::service('date.formatter')->format($entity->changed->value, 'custom', 'd/m/Y');
81+
$row['uuid']['data'] = $entity->uuid();
82+
$row['id']['data'] = $entity->id();
83+
$row['name']['data'] = $entity->toLink();
84+
$row['changed']['data'] = \Drupal::service('date.formatter')->format($entity->changed->value, 'custom', 'd/m/Y');
6385
$status_code = !empty($entity->getStatus()->first()->getValue()) ? $entity->getStatus()->first()->getValue()['value'] : amiSetEntity::STATUS_NOT_READY;
64-
$row['status'] = amiSetEntity::STATUS[strtoupper($status_code)] ?? amiSetEntity::STATUS[amiSetEntity::STATUS_NOT_READY];
86+
$row['status']['data'] = amiSetEntity::STATUS[strtoupper($status_code)] ?? amiSetEntity::STATUS[amiSetEntity::STATUS_NOT_READY];
6587
return $row + parent::buildRow($entity);
6688
}
6789

90+
/**
91+
* @inheritDoc
92+
*/
93+
protected function getEntityListQuery(): QueryInterface {
94+
$query = $this->getStorage()->getQuery()
95+
->accessCheck(TRUE);
96+
$header = $this->buildHeader();
97+
$query->tableSort($header);
98+
// Only add the pager if a limit is specified.
99+
if ($this->limit) {
100+
$query->pager($this->limit);
101+
}
102+
return $query;
103+
}
104+
105+
106+
107+
68108
public function getOperations(EntityInterface $entity) {
69109
$operations = parent::getOperations($entity); // TODO: Change the autogenerated stub
70110
if ($entity->access('process') && $entity->hasLinkTemplate('process-form')) {

src/Entity/amiSetEntity.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@
9292
* "access" = "Drupal\ami\Entity\Controller\amiSetEntityAccessControlHandler",
9393
* },
9494
* base_table = "ami_setentity",
95+
* list_cache_contexts = {"user", "url"},
9596
* admin_permission = "administer amiset entity",
9697
* fieldable = TRUE,
9798
* entity_keys = {

0 commit comments

Comments
 (0)