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.
Comments
Comment #3
bradjones1Comment #4
bradjones1A contrib project that prefers camelCase variables... I love it.
Comment #5
el7cosmosI 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::registerComment #6
pookmish commentedBumping to a critical priority since Sept 1st release is causing this error on the "stable" release.
Comment #7
el7cosmosComment #13
el7cosmosComment #15
rodrigoaguileraThis 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()
Comment #17
el7cosmosThis was fixed in https://git.drupalcode.org/project/hook_event_dispatcher/-/commit/3e9402...