Skip to content

Commit

Permalink
Show edit icon for FLD custom fields with overridden attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonkelly committed Aug 30, 2024
1 parent 8c54e13 commit 1492252
Show file tree
Hide file tree
Showing 3 changed files with 26 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 @@ -12,6 +12,7 @@

### Administration
- Link fields now have “Allow root-relative URLs” and “Allow anchors” settings. ([#15579](https://github.com/craftcms/cms/issues/15579))
- Custom field selectors within field layouts now display a pencil icon if their name, instructions, or handle have been overridden. ([#15597](https://github.com/craftcms/cms/discussions/15597))

### Development
- Added the `notRelatedTo` and `andNotRelatedTo` element query params. ([#15496](https://github.com/craftcms/cms/pull/15496))
Expand Down
24 changes: 24 additions & 0 deletions src/fieldlayoutelements/CustomField.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use craft\base\ThumbableFieldInterface;
use craft\errors\FieldNotFoundException;
use craft\helpers\ArrayHelper;
use craft\helpers\Inflector;
use craft\helpers\StringHelper;

/**
Expand Down Expand Up @@ -278,6 +279,29 @@ protected function selectorIcon(): ?string
return $this->_field::icon();
}

protected function selectorIndicators(): array
{
$indicators = parent::selectorIndicators();

if (isset($this->label) || isset($this->instructions) || isset($this->handle)) {
$attributes = array_values(array_filter([
isset($this->label) ? Craft::t('app', 'Name') : null,
isset($this->instructions) ? Craft::t('app', 'Instructions') : null,
isset($this->handle) ? Craft::t('app', 'Handle') : null,
]));
array_unshift($indicators, [
'label' => Craft::t('app', 'This field’s {attributes} {totalAttributes, plural, =1{has} other{have}} been overridden.', [
'attributes' => mb_strtolower(Inflector::sentence($attributes)),
'totalAttributes' => count($attributes),
]),
'icon' => 'pencil',
'iconColor' => 'teal',
]);
}

return $indicators;
}

/**
* @inheritdoc
*/
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 @@ -1665,6 +1665,7 @@
'This field was updated in the Current revision.' => 'This field was updated in the Current revision.',
'This field’s target subfolder path is invalid: {path}' => 'This field’s target subfolder path is invalid: {path}',
'This field’s values are used as search keywords.' => 'This field’s values are used as search keywords.',
'This field’s {attributes} {totalAttributes, plural, =1{has} other{have}} been overridden.' => 'This field’s {attributes} {totalAttributes, plural, =1{has} other{have}} been overridden.',
'This filesystem has been reserved for temporary asset uploads. Please choose a different one for your volume.' => 'This filesystem has been reserved for temporary asset uploads. Please choose a different one for your volume.',
'This global set doesn’t have any fields assigned to it in its field layout.' => 'This global set doesn’t have any fields assigned to it in its field layout.',
'This is being overridden by the {setting} config setting.' => 'This is being overridden by the {setting} config setting.',
Expand Down

0 comments on commit 1492252

Please sign in to comment.