Skip to content

Commit

Permalink
Include “Country” columns in address indexes
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonkelly committed Sep 10, 2024
1 parent ce92893 commit eb8ea3a
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG-WIP.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
### Content Management
- Improved the styling of element cards with thumbnails. ([#15692](https://github.com/craftcms/cms/pull/15692), [#15673](https://github.com/craftcms/cms/issues/15673))
- Elements within element selection inputs now have “Replace” actions.
- Address index tables can now include “Country” columns.

### Administration
- All relation fields can now be selected as field layouts’ thumbnail providers. ([#15651](https://github.com/craftcms/cms/discussions/15651))
Expand Down
56 changes: 56 additions & 0 deletions src/elements/Address.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,62 @@ public static function createCondition(): ElementConditionInterface
return Craft::createObject(AddressCondition::class, [static::class]);
}

/**
* @inheritdoc
*/
protected static function defineTableAttributes(): array
{
return array_merge(parent::defineTableAttributes(), [
'country' => ['label' => Craft::t('app', 'Country')],
]);
}

/**
* @inheritdoc
*/
protected function attributeHtml(string $attribute): string
{
switch ($attribute) {
case 'country':
return $this->getCountry()->getName();
default:
return parent::attributeHtml($attribute);
}
}

/**
* @inheritdoc
*/
protected static function defineSortOptions(): array
{
return [
[
'label' => Craft::t('app', 'Label'),
'orderBy' => 'title',
'attribute' => 'title',
],
[
'label' => Craft::t('app', 'Country'),
'orderBy' => 'countryCode',
'attribute' => 'country',
],
[
'label' => Craft::t('app', 'Date Created'),
'orderBy' => 'dateCreated',
'defaultDir' => 'desc',
],
[
'label' => Craft::t('app', 'Date Updated'),
'orderBy' => 'dateUpdated',
'defaultDir' => 'desc',
],
[
'label' => Craft::t('app', 'ID'),
'orderBy' => 'id',
],
];
}

/**
* @inheritdoc
* @return AddressQuery The newly created [[AddressQuery]] instance.
Expand Down

0 comments on commit eb8ea3a

Please sign in to comment.