From bf9c66a50e18c6576b39929f11a229f7149c4663 Mon Sep 17 00:00:00 2001 From: brandonkelly Date: Mon, 2 Sep 2024 11:48:49 -0700 Subject: [PATCH] Hide status indicators for entry types w/o status fields Resolves #15636 --- CHANGELOG-WIP.md | 2 ++ src/base/Element.php | 8 ++++++++ src/base/ElementInterface.php | 8 ++++++++ src/elements/Entry.php | 8 ++++++++ src/helpers/Cp.php | 4 ++-- 5 files changed, 28 insertions(+), 2 deletions(-) diff --git a/CHANGELOG-WIP.md b/CHANGELOG-WIP.md index d30755705b6..4b9f60d5724 100644 --- a/CHANGELOG-WIP.md +++ b/CHANGELOG-WIP.md @@ -7,6 +7,7 @@ - Category slugs are now inline-editable from the Categories index page. ([#15560](https://github.com/craftcms/cms/pull/15560)) - Entry post dates, expiry dates, slugs, and authors are now inline-editable from the Entries index page. ([#15560](https://github.com/craftcms/cms/pull/15560)) - Improved Addresses field validation to be more consistent with Matrix fields. +- Entry chips and cards no longer include status indicators, if their entry type’s “Show thet Status field” setting is disabled. ([#15636](https://github.com/craftcms/cms/discussions/15636)) ### Accessibility - Improved the accessibility of Tags fields. @@ -30,6 +31,7 @@ ### Extensibility - Added `craft\base\ApplicationTrait::getEnvId()`. ([#15313](https://github.com/craftcms/cms/issues/15313)) - Added `craft\base\ElementInterface::getRootOwner()`. ([#15534](https://github.com/craftcms/cms/discussions/15534)) +- Added `craft\base\ElementInterface::showStatusIndicator()`. - Added `craft\elements\conditions\NotRelatedToConditionRule`. - Added `craft\elements\conditions\SiteGroupConditionRule`. - Added `craft\gql\arguments\RelationCriteria`. diff --git a/src/base/Element.php b/src/base/Element.php index c9cd03003a0..ee8915a017e 100644 --- a/src/base/Element.php +++ b/src/base/Element.php @@ -3284,6 +3284,14 @@ public function getChipLabelHtml(): string return Html::encode($this->getUiLabel()); } + /** + * @inheritdoc + */ + public function showStatusIndicator(): bool + { + return static::hasStatuses(); + } + /** * @inheritdoc */ diff --git a/src/base/ElementInterface.php b/src/base/ElementInterface.php index d92ae4a641b..a4d3504eb6c 100644 --- a/src/base/ElementInterface.php +++ b/src/base/ElementInterface.php @@ -790,6 +790,14 @@ public function setUiLabelPath(array $path): void; */ public function getChipLabelHtml(): string; + /** + * Returns whether chips and cards for this element should include a status indicator. + * + * @return bool + * @since 5.4.0 + */ + public function showStatusIndicator(): bool; + /** * Returns the body HTML for element cards. * diff --git a/src/elements/Entry.php b/src/elements/Entry.php index c7ce289ed0c..7301369503c 100644 --- a/src/elements/Entry.php +++ b/src/elements/Entry.php @@ -1184,6 +1184,14 @@ public function getChipLabelHtml(): string ]); } + /** + * @inheritdoc + */ + public function showStatusIndicator(): bool + { + return $this->getType()->showStatusField; + } + /** * @inheritdoc */ diff --git a/src/helpers/Cp.php b/src/helpers/Cp.php index cf611e9fd6a..246f0f0a3aa 100644 --- a/src/helpers/Cp.php +++ b/src/helpers/Cp.php @@ -512,7 +512,7 @@ public static function elementChipHtml(ElementInterface $element, array $config $config['attributes'], ); - $config['showStatus'] = $config['showStatus'] && ($element->getIsDraft() || $element::hasStatuses()); + $config['showStatus'] = $config['showStatus'] && ($element->getIsDraft() || $element->showStatusIndicator()); if ($config['showLabel']) { $config['labelHtml'] = self::elementLabelHtml( @@ -611,7 +611,7 @@ public static function elementCardHtml(ElementInterface $element, array $config $bodyContent = $element->getCardBodyHtml() ?? ''; $labels = array_filter([ - $element::hasStatuses() ? static::componentStatusLabelHtml($element) : null, + $element->showStatusIndicator() ? static::componentStatusLabelHtml($element) : null, $element->isProvisionalDraft ? self::changeStatusLabelHtml() : null, ]);