Prevent PHP notice "Undefined index: callback_object" if calling FormState::getFormObject() when the form object is not yet set

Created on 26 July 2017, about 7 years ago
Updated 16 February 2024, 7 months ago

Problem/Motivation

The public method FormState::getFormObject() directly retrieves the callback object from the build info array without checking if it is present and in the cases where it is not yet set then a PHP notice will be raised:

"Notice: Undefined index: callback_object in Drupal\Core\Form\FormState->getFormObject() (line 1166 of core/lib/Drupal/Core/Form/FormState.php)."

Proposed resolution

Throw an exception when the form object is not stored on the form state.
Consider also adding a new method ::hasFormObject()

Remaining tasks

Determine steps to reproduce/use case
Consider adding ::hasFormObject() based on the use case

User interface changes

N/A

API changes

Replace undefined index error with exception

Data model changes

N/A

πŸ› Bug report
Status

Closed: outdated

Version

11.0 πŸ”₯

Component
FormΒ  β†’

Last updated 1 minute ago

Created by

πŸ‡©πŸ‡ͺGermany hchonov πŸ‡ͺπŸ‡ΊπŸ‡©πŸ‡ͺπŸ‡§πŸ‡¬

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.

  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Was previously tagged for steps but those were never added. Adding tag back.

    The patch seems to be fixing the symptom vs the cause so could use those steps to maybe track down what's causing this.

  • Status changed to Postponed: needs info over 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    that seems like a more appropriate status actually.

  • Status changed to Closed: outdated 7 months ago
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    If still a valid bug please reopen adding steps to reproduce to the summary please

    Thansk.

Production build 0.71.5 2024