'...', 'fieldName' => 'email', 'fieldId' => 'email'] * - FormErrors::toArray()-like map: ['email' => ['Required']] */ $validationSummaryErrorsRaw = $validationSummaryErrors ?? ($errors ?? []); if (!is_array($validationSummaryErrorsRaw)) { $validationSummaryErrorsRaw = []; } $validationSummaryTitle = isset($validationSummaryTitle) ? trim((string) $validationSummaryTitle) : t('Please review the following errors'); $validationSummaryAutoFocus = !isset($validationSummaryAutoFocus) ? true : !empty($validationSummaryAutoFocus); $validationSummaryItems = []; $pushValidationSummaryItem = static function ( array &$items, string $message, string $fieldName = '', string $fieldId = '', string $href = '' ): void { $message = trim($message); if ($message === '') { return; } $items[] = [ 'message' => $message, 'fieldName' => trim($fieldName), 'fieldId' => trim($fieldId), 'href' => trim($href), ]; }; foreach ($validationSummaryErrorsRaw as $errorKey => $entry) { $keyFieldName = is_string($errorKey) ? trim($errorKey) : ''; if ($keyFieldName === 'input') { $keyFieldName = ''; } if (is_array($entry)) { if (array_is_list($entry)) { foreach ($entry as $listMessage) { if (!is_scalar($listMessage)) { continue; } $pushValidationSummaryItem( $validationSummaryItems, (string) $listMessage, $keyFieldName ); } continue; } $message = ''; if (isset($entry['message'])) { $message = (string) $entry['message']; } elseif (isset($entry['text'])) { $message = (string) $entry['text']; } elseif (isset($entry['label'])) { $message = (string) $entry['label']; } else { foreach ($entry as $candidate) { if (is_scalar($candidate)) { $message = (string) $candidate; break; } } } $fieldName = ''; if (isset($entry['fieldName'])) { $fieldName = (string) $entry['fieldName']; } elseif (isset($entry['field_name'])) { $fieldName = (string) $entry['field_name']; } elseif (isset($entry['field'])) { $fieldName = (string) $entry['field']; } elseif (isset($entry['name'])) { $fieldName = (string) $entry['name']; } elseif ($keyFieldName !== '') { $fieldName = $keyFieldName; } if (trim($fieldName) === 'input') { $fieldName = ''; } $fieldId = isset($entry['fieldId']) ? (string) $entry['fieldId'] : (string) ($entry['field_id'] ?? ''); $href = (string) ($entry['href'] ?? ''); $pushValidationSummaryItem($validationSummaryItems, $message, $fieldName, $fieldId, $href); continue; } if (is_scalar($entry)) { $pushValidationSummaryItem( $validationSummaryItems, (string) $entry, $keyFieldName ); } } if (!$validationSummaryItems) { return; } ?>