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
20 changes: 19 additions & 1 deletion src/controllers/ElementsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use craft\events\DefineElementEditorHtmlEvent;
use craft\events\DraftEvent;
use craft\fieldlayoutelements\BaseField;
use craft\fieldlayoutelements\CustomField;
use craft\fields\Matrix;
use craft\helpers\ArrayHelper;
use craft\helpers\Component;
Expand Down Expand Up @@ -1046,6 +1047,9 @@ private function _errorSummary(ElementInterface $element): string
$errorItem .= $error;
$errorItem .= Html::endTag('li');
} else {
// is the error for multi-nested field (e.g. matrix in a matrix in a blocks mode)
$multiNested = substr_count($key, '.') > 1;

// get tab uid for this error
$tabUid = null;
$bracketPos = strpos($key, '[');
Expand All @@ -1054,7 +1058,21 @@ private function _errorSummary(ElementInterface $element): string
foreach ($tab->getElements() as $layoutElement) {
if ($layoutElement instanceof BaseField && $layoutElement->attribute() === $fieldKey) {
$tabUid = $tab->uid;
continue 2;
if (!$multiNested) {
continue 2;
}
}
// if it's a multi-nested error key for matrix in blocks mode
// manipulate the key to only reference the matrix field, entry and inner field
if ($multiNested && $layoutElement instanceof CustomField) {
if (
$layoutElement->getField() instanceof Matrix &&
$layoutElement->getField()->viewMode === Matrix::VIEW_MODE_BLOCKS
brandonkelly marked this conversation as resolved.
Show resolved Hide resolved
) {
$keyParts = explode('.', $key);
$key = implode('.', array_splice($keyParts, -2));
unset($keyParts);
}
}
}
}
Expand Down
Loading