Skip to content

Commit

Permalink
“Parent” column for entry & category indexes
Browse files Browse the repository at this point in the history
Resolves #12666
  • Loading branch information
brandonkelly committed Feb 13, 2023
1 parent 0c890b0 commit c094566
Show file tree
Hide file tree
Showing 4 changed files with 10 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 @@ -5,6 +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))
- 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
7 changes: 7 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 'parent':
$elementQuery->andWith(['parent', ['status' => null]]);
break;
case 'revisionNotes':
$elementQuery->andWith('currentRevision');
break;
Expand Down Expand Up @@ -4471,6 +4474,10 @@ public function getTableAttributeHtml(string $attribute): string
protected function tableAttributeHtml(string $attribute): string
{
switch ($attribute) {
case 'parent':
$parent = $this->getParent();
return $parent ? Cp::elementHtml($parent) : '';

case 'link':
if (ElementHelper::isDraftOrRevision($this)) {
return '';
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 [
'parent' => ['label' => Craft::t('app', 'Parent')],
'slug' => ['label' => Craft::t('app', 'Slug')],
'uri' => ['label' => Craft::t('app', 'URI')],
'link' => ['label' => Craft::t('app', 'Link'), 'icon' => 'world'],
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')],
'parent' => ['label' => Craft::t('app', 'Parent')],
'uri' => ['label' => Craft::t('app', 'URI')],
'postDate' => ['label' => Craft::t('app', 'Post Date')],
'expiryDate' => ['label' => Craft::t('app', 'Expiry Date')],
Expand Down

0 comments on commit c094566

Please sign in to comment.