Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG-WIP.md
Original file line number Diff line number Diff line change
@@ -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))
Expand Down
6 changes: 5 additions & 1 deletion src/base/conditions/BaseCondition.php
Original file line number Diff line number Diff line change
Expand Up @@ -467,13 +467,15 @@ private function _ruleTypeMenu(
if ($rule) {
$label = $rule->getLabel();
$hint = $rule->getLabelHint();
$showHint = $rule->showLabelHint();
$key = $label . ($hint !== null ? " - $hint" : '');
$groupLabel = $rule->getGroupLabel() ?? '__UNGROUPED__';

$groupedRuleTypeOptions[$groupLabel] = [
[
'label' => $label,
'hint' => $hint,
'showHint' => $showHint,
'value' => $ruleValue,
],
];
Expand All @@ -483,13 +485,15 @@ 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__';

if (!isset($labelsByGroup[$groupLabel][$key])) {
$groupedRuleTypeOptions[$groupLabel][] = [
'label' => $label,
'hint' => $hint,
'showHint' => $showHint,
'value' => $value,
];
$labelsByGroup[$groupLabel][$key] = true;
Expand Down Expand Up @@ -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',
Expand Down
8 changes: 8 additions & 0 deletions src/base/conditions/BaseConditionRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ public function getLabelHint(): ?string
return null;
}

/**
* @inheritdoc
*/
public function showLabelHint(): bool
{
return false;
}

/**
* @var string|null UUID
*/
Expand Down
8 changes: 8 additions & 0 deletions src/base/conditions/ConditionRuleInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
12 changes: 9 additions & 3 deletions src/fields/conditions/FieldConditionRuleTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down