diff --git a/CHANGELOG-WIP.md b/CHANGELOG-WIP.md index fd0c4faf149..e342d49d4ab 100644 --- a/CHANGELOG-WIP.md +++ b/CHANGELOG-WIP.md @@ -1,5 +1,8 @@ # Release Notes for Craft CMS 4.16 (WIP) +### Content Management +- Element condition builders now show condition rules for custom fields with duplicate names. ([#17361](https://github.com/craftcms/cms/pull/17361)) + ### Administration - Assets and Categories fields no longer have “Show the site menu” settings. ([#17156](https://github.com/craftcms/cms/issues/17156)) - Improved the wording of validation errors caused by relational fields’ “Validate related [type]” settings. ([#9960](https://github.com/craftcms/cms/discussions/9960)) diff --git a/src/base/conditions/BaseCondition.php b/src/base/conditions/BaseCondition.php index 79ea3a8dac6..4c9dea30083 100644 --- a/src/base/conditions/BaseCondition.php +++ b/src/base/conditions/BaseCondition.php @@ -467,6 +467,7 @@ private function _ruleTypeMenu( if ($rule) { $label = $rule->getLabel(); $hint = $rule->getLabelHint(); + $showHint = $rule->showLabelHint(); $key = $label . ($hint !== null ? " - $hint" : ''); $groupLabel = $rule->getGroupLabel() ?? '__UNGROUPED__'; @@ -474,6 +475,7 @@ private function _ruleTypeMenu( [ 'label' => $label, 'hint' => $hint, + 'showHint' => $showHint, 'value' => $ruleValue, ], ]; @@ -483,6 +485,7 @@ private function _ruleTypeMenu( foreach ($selectableRules as $value => $selectableRule) { $label = $selectableRule->getLabel(); $hint = $selectableRule->getLabelHint(); + $showHint = $selectableRule->showLabelHint(); $key = $label . ($hint !== null ? " - $hint" : ''); $groupLabel = $selectableRule->getGroupLabel() ?? '__UNGROUPED__'; @@ -490,6 +493,7 @@ private function _ruleTypeMenu( $groupedRuleTypeOptions[$groupLabel][] = [ 'label' => $label, 'hint' => $hint, + 'showHint' => $showHint, 'value' => $value, ]; $labelsByGroup[$groupLabel][$key] = true; @@ -517,7 +521,7 @@ private function _ruleTypeMenu( $html = Html::beginTag('li'); $label = Html::encode($option['label']); - if ($option['hint'] !== null) { + if ($option['showHint'] && $option['hint'] !== null) { $label .= ' ' . Html::tag('span', sprintf('– %s', Html::encode($option['hint'])), [ 'class' => 'light', diff --git a/src/base/conditions/BaseConditionRule.php b/src/base/conditions/BaseConditionRule.php index e31172d9503..bd15e053025 100644 --- a/src/base/conditions/BaseConditionRule.php +++ b/src/base/conditions/BaseConditionRule.php @@ -52,6 +52,14 @@ public function getLabelHint(): ?string return null; } + /** + * @inheritdoc + */ + public function showLabelHint(): bool + { + return false; + } + /** * @var string|null UUID */ diff --git a/src/base/conditions/ConditionRuleInterface.php b/src/base/conditions/ConditionRuleInterface.php index 250d15a958a..2639ba0e5cd 100644 --- a/src/base/conditions/ConditionRuleInterface.php +++ b/src/base/conditions/ConditionRuleInterface.php @@ -41,6 +41,14 @@ public function getLabel(): string; */ public function getLabelHint(): ?string; + /** + * Returns whether to show rule’s option label hint. + * + * @return bool + * @since 4.16.0 + */ + public function showLabelHint(): bool; + /** * Returns the optgroup label the condition rule should be grouped under. * diff --git a/src/fields/conditions/FieldConditionRuleTrait.php b/src/fields/conditions/FieldConditionRuleTrait.php index 857858a323f..ed06d521a85 100644 --- a/src/fields/conditions/FieldConditionRuleTrait.php +++ b/src/fields/conditions/FieldConditionRuleTrait.php @@ -97,9 +97,15 @@ public function getLabel(): string */ public function getLabelHint(): ?string { - static $showHandles = null; - $showHandles ??= Craft::$app->getUser()->getIdentity()?->getPreference('showFieldHandles') ?? false; - return $showHandles ? $this->field()->handle : null; + return $this->field()->handle; + } + + /** + * @inheritdoc + */ + public function showLabelHint(): bool + { + return Craft::$app->getUser()->getIdentity()?->getPreference('showFieldHandles') ?? false; } /**