Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

anchor summary error to field for nested matrix "blocks" #15811

Merged
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- Fixed a bug where element sources weren’t keyboard-selectable. ([#15876](https://github.com/craftcms/cms/issues/15876))
- Fixed a bug where Craft wasn’t auto-detecting interactive terminals on Windows.
- Fixed a bug where element actions were allowed on nested entries when viewing a revision. ([#15879](https://github.com/craftcms/cms/pull/15879))
- Fixed a bug where element error summaries weren’t linking to recursively-nested Matrix fields properly. ([#15797](https://github.com/craftcms/cms/issues/15797))

## 5.4.7.1 - 2024-10-09

Expand Down
11 changes: 11 additions & 0 deletions src/controllers/ElementsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -1059,6 +1059,17 @@ private function _errorSummary(ElementInterface $element): string
}
}

// If the error is for a recursively-nested Matrix field,
// manipulate the key to only reference the nested Matrix field, entry and inner field
// Before: foo[<uuid>].bar[<uuid>].baz
// After: bar[<uuid>].baz
if (substr_count($key, '.') > 1) {
$keyParts = explode('.', $key);
if (preg_match(sprintf('/\[%s\]$/', StringHelper::UUID_PATTERN), $keyParts[count($keyParts) - 3])) {
$key = implode('.', array_slice($keyParts, -2));
}
}

$errorItem = null;
if ($error !== null) {
$error = Markdown::processParagraph(htmlspecialchars($error));
Expand Down