Skip to content

Commit

Permalink
“Ancestors” column for entry & category indexes
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonkelly committed Feb 14, 2023
1 parent d0cd5b9 commit 7fafcf9
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CHANGELOG-WIP.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
- Asset indexes now display the current subfolder path above the element listing. ([#12558](https://github.com/craftcms/cms/pull/12558))
- It’s now possible to move volume folders and assets to a new location via a new “Move…” bulk element action, rather than via drag-and-drop interactions. ([#12558](https://github.com/craftcms/cms/pull/12558))
- It’s now possible to sort asset indexes by image width and height. ([#12653](https://github.com/craftcms/cms/pull/12653))
- Entry and category indexes can now have a “Parent” column. ([#12666](https://github.com/craftcms/cms/discussions/12666))
- Entry and category indexes can now have “Ancestors” and “Parent” columns. ([#12666](https://github.com/craftcms/cms/discussions/12666))
- All element sources now have a “Duplicate” action, even if the element type’s `defineActions()` method didn’t include one. ([#12382](https://github.com/craftcms/cms/discussions/12382))
- Element index pages now track the search term in a query param, so the results can be shared. ([#8942](https://github.com/craftcms/cms/discussions/8942), [#12399](https://github.com/craftcms/cms/pull/12399))
- Entries with more than 10 revisions now include a “View all revisions” item within their revision menu, which links to a new revisions index page for the entry that paginates through all its revisions. ([#8609](https://github.com/craftcms/cms/discussions/8609))
Expand Down
14 changes: 14 additions & 0 deletions src/base/Element.php
Original file line number Diff line number Diff line change
Expand Up @@ -1144,6 +1144,9 @@ public static function indexHtml(ElementQueryInterface $elementQuery, ?array $di
protected static function prepElementQueryForTableAttribute(ElementQueryInterface $elementQuery, string $attribute): void
{
switch ($attribute) {
case 'ancestors':
$elementQuery->andWith(['ancestors', ['status' => null]]);
break;
case 'parent':
$elementQuery->andWith(['parent', ['status' => null]]);
break;
Expand Down Expand Up @@ -4474,6 +4477,17 @@ public function getTableAttributeHtml(string $attribute): string
protected function tableAttributeHtml(string $attribute): string
{
switch ($attribute) {
case 'ancestors':
$ancestors = $this->getAncestors();
if (!$ancestors instanceof Collection || $ancestors->isEmpty()) {
return '';
}
$html = Html::beginTag('ul', ['class' => 'path']);
foreach ($ancestors as $ancestor) {
$html .= Html::tag('li', Cp::elementHtml($ancestor));
}
return $html . Html::endTag('ul');

case 'parent':
$parent = $this->getParent();
return $parent ? Cp::elementHtml($parent) : '';
Expand Down
1 change: 1 addition & 0 deletions src/elements/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ protected static function defineSortOptions(): array
protected static function defineTableAttributes(): array
{
return [
'ancestors' => ['label' => Craft::t('app', 'Ancestors')],
'parent' => ['label' => Craft::t('app', 'Parent')],
'slug' => ['label' => Craft::t('app', 'Slug')],
'uri' => ['label' => Craft::t('app', 'URI')],
Expand Down
1 change: 1 addition & 0 deletions src/elements/Entry.php
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,7 @@ protected static function defineTableAttributes(): array
'type' => ['label' => Craft::t('app', 'Entry Type')],
'author' => ['label' => Craft::t('app', 'Author')],
'slug' => ['label' => Craft::t('app', 'Slug')],
'ancestors' => ['label' => Craft::t('app', 'Ancestors')],
'parent' => ['label' => Craft::t('app', 'Parent')],
'uri' => ['label' => Craft::t('app', 'URI')],
'postDate' => ['label' => Craft::t('app', 'Post Date')],
Expand Down
1 change: 1 addition & 0 deletions src/translations/en/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@
'An error occurred when duplicating the entry.' => 'An error occurred when duplicating the entry.',
'An error occurred when installing {name}.' => 'An error occurred when installing {name}.',
'An error occurred while processing your request.' => 'An error occurred while processing your request.',
'Ancestors' => 'Ancestors',
'Announcements' => 'Announcements',
'Any changes will be lost if you leave this page.' => 'Any changes will be lost if you leave this page.',
'Anything cached with `Craft::$app->cache->set()`' => 'Anything cached with `Craft::$app->cache->set()`',
Expand Down

0 comments on commit 7fafcf9

Please sign in to comment.