FormState::setErrorByName is inconsistent with other methods

Created on 13 September 2014, almost 10 years ago
Updated 1 February 2024, 7 months ago

Problem/Motivation

FormState::setErrorByName() always takes a string as the first parameter, separated by ][ if the element to be set is nested below the top level of the form structure. All other new form state methods such as get, set, getValue, etc. take an array instead when dealing with nested structures.

Steps to reproduce

Proposed resolution

Check if $name is passed as an array and if so, implode its components into a string.

Remaining tasks

TBA

User interface changes

API changes

Data model changes

Release notes snippet

πŸ“Œ Task
Status

Needs work

Version

9.5

Component
FormΒ  β†’

Last updated less than a minute ago

Created by

πŸ‡¬πŸ‡§United Kingdom longwave UK

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡³πŸ‡ΏNew Zealand quietone New Zealand

    This would be a nice change but it is not a bug, changing to a task. For fun, I updated the patch but it still needs work and I see there is a suggestion for a Unit test instead.

  • πŸ‡¬πŸ‡§United Kingdom alexpott πŸ‡ͺπŸ‡ΊπŸŒ

    What's wrong with \Drupal\Core\Form\FormState::setError() - this implementation is

      /**
       * {@inheritdoc}
       */
      public function setError(array &$element, $message = '') {
        $this->setErrorByName(implode('][', $element['#parents']), $message);
        return $this;
      }
    

    I think this should be closed as outdated.

  • πŸ‡¦πŸ‡ΊAustralia sime Canberra
Production build 0.71.5 2024