Verified Commit ffaad163 authored by Luhur Abdi Rizal's avatar Luhur Abdi Rizal Committed by Luhur Abdi Rizal
Browse files

Issue #3294805 by el7cosmos, bradjones1: Handle forms without base form ID

parent 63037c41
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -39,6 +39,10 @@ class FormBaseAlterEvent extends AbstractFormEvent {
    parent::__construct($form, $formState, $formId);
    $buildInfo = $formState->getBuildInfo();
    $this->baseFormId = $buildInfo['base_form_id'] ?? NULL;

    if (!$this->baseFormId) {
      $this->stopPropagation();
    }
  }

  /**
+20 −2
Original line number Diff line number Diff line
@@ -37,8 +37,26 @@ class FormEventTest extends KernelTestBase {
    $this->listen([
      FormHookEvents::FORM_ALTER,
      'hook_event_dispatcher.form_test_form.alter',
      'hook_event_dispatcher.form_base_test_base_form.alter',
    ], 'onFormAlter', $this->exactly(3));
    ], 'onFormAlter', $this->exactly(2));

    $form = [
      'test' => 'form',
    ];

    $formState = new FormState();
    $formState->set('test', TRUE);

    $this->container->get('form_builder')->prepareForm('test_form', $form, $formState);
    $this->assertEquals('test_altered', $form['test']);
  }

  /**
   * Test form base alter event.
   *
   * @throws \Exception
   */
  public function testFormBaseAlterEvent(): void {
    $this->listen('hook_event_dispatcher.form_base_test_base_form.alter', 'onFormAlter');

    $form = [
      'test' => 'form',
+6 −0
Original line number Diff line number Diff line
@@ -27,6 +27,12 @@ class HookEventDispatcherManager implements HookEventDispatcherManagerInterface
   * {@inheritdoc}
   */
  public function register(EventInterface $event): Event {
    assert($event instanceof Event);
    if ($event->isPropagationStopped()) {
      return $event;
    }

    /** @var \Drupal\Component\EventDispatcher\Event */
    return $this->eventDispatcher->dispatch($event, $event->getDispatcherType());
  }