API page: https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Form%21Fo...

Problem / Motivation

The documentation for \Drupal\Core\Form\FormBuilder::setErrorByName() looks like it needs to get an update. It currently makes a bunch of references to form_set_error() which is currently just a wrapper for ::setErrorByName and is also deprecated and slated to be removed.

At a minimum the documentation needs to be updated to remove reference to form_set_error() and replace it with FormBuilder::setErrorByName().

It also looks like this documentation was just copy/pasted from the old Drupal 7 form_set_error function so it's probably in-need of a thorough review to make sure it's still accurate and that the examples are still good.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jhodgdon’s picture

Issue tags: +Novice

Good catch!

This is probably a good Novice project? My suggestion would be to replace references to form_set_error() in text to say "this method" or "of this method", as appropriate (some slight wording or word order changes may also be necessary). And then if specific calls are being made, replace it by FormBuilder::setErrorByName().

Other things I think would be good to fix:
- Where references are made to methods like "...and the submitdoCheckErrors handlers will run...", ?!? Make sure this refers to the correct method name, and it should be something like FormBuilder::methodName() [prefixed by FormBuilder:: and suffixed by ()]
- The two drupal.org links that are there with @see should be removed. They are linking to issues, which are generally not helpful for people to be linked to. Either just remove them, or find appropriate documentation pages to link to.

cs_shadow’s picture

Status: Active » Needs review
FileSize
3.48 KB

Did following changes in the patch:

1. Replaced references to form_set_error() in text to say "this method" or "of this method", as appropriate. Replaced specific calls to form_set_error() by FormBuilder::setErrorByName().

2. Replaced references to form_set_error() by FormBuilder::getError() and form_set_errors() by FormBuilder::getErrors().

3. Replaced reference to submitdoCheckErrors by FormBuildersubmitdoCheckErrors()

Let me know if anything else is required here.

jhodgdon’s picture

Status: Needs review » Needs work

Thanks, this looks really great!

One thing: (my bad!) -- I just noticed this change is on FormErrorInterface(), not FormBuilder(). So instead of linking to FormBuilder:: methods, we should link to FormErrorInterface:: methods. Like here:

+   * calls to FormBuilder::setErrorByName('step1', $form_state, $message) or
+   * FormBuilder::setErrorByName('step1][choice', $form_state, $message) will

and also the later references to getError() and getErrors().

One other thing: There is no such thing (as far as I can tell) as FormBuilder::submitdoCheckErrors() . I really don't have any idea what that was supposed to be? Let's see... Here's the current docs:

   * suppressed, resulting in the message not being displayed to the user, and
   * the submitdoCheckErrors handlers will run despite $form_state['values']['step2'] and
   * $form_state['values']['step2']['groupX']['choiceY'] containing invalid
   * values. Errors for an invalid $form_state['values']['foo'] will be
   * suppressed, but errors flagging invalid values for

All I can think of is that "submitdoCheckErrors" was supposed to be just "submit" here. That would actually make sense to me. So the change in the patch to make this FormBuilder::submitdoCheckErrors() is not quite right. Again, my bad!

cs_shadow’s picture

Did changes as suggested in #3. Sorry to have overlooked the class names earlier. I don't understand what submitdoCheckErrors was supposed to mean, so for now I've changed it to just 'submit'. Let me know if this works.

cs_shadow’s picture

Status: Needs work » Needs review
cs_shadow’s picture

FileSize
3.51 KB
2.32 KB

Missed an instance in the last patch.

filijonka’s picture

Status: Needs review » Reviewed & tested by the community

looks ok for me

jhodgdon’s picture

Thanks! Looks good to me too.

jhodgdon’s picture

Status: Reviewed & tested by the community » Fixed

Thanks again! Committed to 8.x.

  • Commit 02eb3d3 on 8.x by jhodgdon:
    Issue #2257283 by cs_shadow, filijonka: Fix obsolete references to...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.