Skip to content
Snippets Groups Projects

Issue #3083103: Programmatically associate error messages with inputs

Open Issue #3083103: Programmatically associate error messages with inputs
3 unresolved threads
3 unresolved threads

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
23 protected $renderer;
24
25 /**
26 * Constructs a FormErrorHandler instance.
27 *
28 * @param \Drupal\Core\Render\RendererInterface $renderer
29 * The renderer service.
30 */
31 public function __construct(RendererInterface $renderer) {
32 $this->renderer = $renderer;
33 }
34
35 /**
36 * {@inheritdoc}
37 */
38 public static function create(ContainerInterface $container) {
  • 39 67 */
    40 68 protected function displayErrorMessages(array $form, FormStateInterface $form_state) {
    41 69 $errors = $form_state->getErrors();
    42
    43 // Loop through all form errors and set an error message.
    44 foreach ($errors as $error) {
    45 $this->messenger()->addMessage($error, 'error');
    70 $items = [
    71 '#theme' => 'item_list',
  • 45 $this->messenger()->addMessage($error, 'error');
    70 $items = [
    71 '#theme' => 'item_list',
    72 '#items' => [],
    73 '#list_type' => 'ul',
    74 ];
    75 // Loop through all form errors and sets an ID & error messages.
    76 foreach ($errors as $name => $error) {
    77 $form_element = FormElementHelper::getElementByName($name, $form);
    78 $has_id = !empty($form_element['#id']);
    79 if ($has_id) {
    80 $items['#wrapper_attributes'] = [
    81 'id' => $form_element['#id'] . '--error-message',
    82 ];
    83 }
    84 $message = [
  • James Gilliland added 3744 commits

    added 3744 commits

    Compare with previous version

  • Liam Morland changed the description

    changed the description

  • Liam Morland changed target branch from 9.3.x to 11.x

    changed target branch from 9.3.x to 11.x

  • Liam Morland added 1074 commits

    added 1074 commits

    Compare with previous version

  • Liam Morland added 1 commit

    added 1 commit

    Compare with previous version

  • Liam Morland added 1 commit

    added 1 commit

    • b48dd357 - Remove unused `use` statement

    Compare with previous version

  • Please register or sign in to reply
    Loading