Skip to content

Commit 3653257

Browse files
committed
Fix table columns and sorting for Wishlist items in the control panel
1 parent 84eb719 commit 3653257

File tree

1 file changed

+38
-10
lines changed

1 file changed

+38
-10
lines changed

src/elements/Item.php

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -82,33 +82,52 @@ protected static function defineActions(string $source = null): array
8282

8383
protected static function defineSearchableAttributes(): array
8484
{
85-
return ['title', 'elementDisplay'];
85+
return ['title', 'elementClass'];
8686
}
8787

8888
protected static function defineSortOptions(): array
8989
{
9090
return [
91-
'title' => Craft::t('app', 'Item'),
92-
'elementDisplay' => Craft::t('app', 'Type'),
93-
'dateCreated' => Craft::t('app', 'Date Created'),
91+
[
92+
'label' => Craft::t('app', 'Title'),
93+
'orderBy' => 'elementTitle',
94+
'attribute' => 'title',
95+
],
96+
[
97+
'label' => Craft::t('app', 'Type'),
98+
'orderBy' => 'elementClass',
99+
'attribute' => 'elementClass',
100+
],
101+
[
102+
'label' => Craft::t('app', 'Date Created'),
103+
'orderBy' => 'dateCreated',
104+
'defaultDir' => 'desc',
105+
],
106+
[
107+
'label' => Craft::t('app', 'Date Updated'),
108+
'orderBy' => 'dateUpdated',
109+
'defaultDir' => 'desc',
110+
],
111+
[
112+
'label' => Craft::t('app', 'ID'),
113+
'orderBy' => 'id',
114+
],
94115
];
95116
}
96117

97118
protected static function defineTableAttributes(): array
98119
{
99-
return [
100-
'title' => ['label' => Craft::t('app', 'Item')],
101-
'elementDisplay' => ['label' => Craft::t('app', 'Type')],
102-
'dateCreated' => ['label' => Craft::t('app', 'Date Created')],
103-
];
120+
return array_merge(parent::defineTableAttributes(), [
121+
'elementClass' => ['label' => Craft::t('app', 'Type')],
122+
]);
104123
}
105124

106125
protected static function defineDefaultTableAttributes(string $source): array
107126
{
108127
$attributes = [];
109128

110129
$attributes[] = 'title';
111-
$attributes[] = 'elementDisplay';
130+
$attributes[] = 'elementClass';
112131
$attributes[] = 'dateCreated';
113132

114133
return $attributes;
@@ -429,4 +448,13 @@ protected function cpEditUrl(): ?string
429448
{
430449
return UrlHelper::cpUrl('wishlist/lists/' . $this->getList()->getType()->handle . '/' . $this->listId . '/items/' . $this->id);
431450
}
451+
452+
protected function attributeHtml(string $attribute): string
453+
{
454+
if ($attribute == 'elementClass') {
455+
return $this->getElementDisplay();
456+
}
457+
458+
return parent::attributeHtml($attribute);
459+
}
432460
}

0 commit comments

Comments
 (0)