Problem/Motivation

Some forms do not have a base form ID. In this case, FormBaseAlterEvent::getBaseFormId() raises a type error because it would return NULL.

Since the refactoring in #3277301: Adapt to centralised hook dispatcher in Drupal 9.4, it seems like we need some way for events to state they should not dispatch.

Steps to reproduce

Attempt to render a form with no base form (it does not extend an existing form.)

Proposed resolution

Provide a method for events to short-circuit dispatching in ::getDispatcherType().

Remaining tasks

Review, tests?

User interface changes

None

API changes

Some return types are now nullable.

Data model changes

None.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

bradjones1 created an issue. See original summary.

bradjones1’s picture

Status: Active » Needs review
Issue tags: +Needs tests
bradjones1’s picture

A contrib project that prefers camelCase variables... I love it.

el7cosmos’s picture

Status: Needs review » Needs work

I would probably throwing exception here, something like WontDispatchException, instead of allowing null in \Drupal\hook_event_dispatcher\Event\EventInterface::getDispatcherType, and catch the exception in \Drupal\hook_event_dispatcher\Manager\HookEventDispatcherManager::register

pookmish’s picture

Priority: Normal » Critical

Bumping to a critical priority since Sept 1st release is causing this error on the "stable" release.

el7cosmos’s picture

Version: 3.x-dev » 3.3.0
Assigned: Unassigned » el7cosmos

  • el7cosmos committed 57db4ff on 3.x
    Issue #3294805 by el7cosmos, bradjones1: Handle forms without base form...

el7cosmos credited f0ns.

el7cosmos credited RandalV.

el7cosmos’s picture

Status: Needs work » Fixed

  • el7cosmos committed ffaad16 on 4.x
    Issue #3294805 by el7cosmos, bradjones1: Handle forms without base form...
rodrigoaguilera’s picture

Version: 3.3.0 » 4.x-dev
Status: Fixed » Needs work

This fix is not going to work for the future 4.x branch because the property $baseFormId is declared as a string so you can not even assign NULL to it.
TypeError: Cannot assign null to property Drupal\core_event_dispatcher\Event\Form\FormBaseAlterEvent::$baseFormId of type string in Drupal\core_event_dispatcher\Event\Form\FormBaseAlterEvent->__construct()

  • el7cosmos committed ffaad163 on gitlab-ci
    Issue #3294805 by el7cosmos, bradjones1: Handle forms without base form...
el7cosmos’s picture

Assigned: el7cosmos » Unassigned
Status: Needs work » Fixed

This fix is not going to work for the future 4.x branch because the property $baseFormId is declared as a string so you can not even assign NULL to it.

This was fixed in https://git.drupalcode.org/project/hook_event_dispatcher/-/commit/3e9402...

Status: Fixed » Closed (fixed)

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