diff --git a/core/lib/Drupal/Core/Form/FormAlter.php b/core/lib/Drupal/Core/Form/FormAlter.php index ed418ff..49f3062 100644 --- a/core/lib/Drupal/Core/Form/FormAlter.php +++ b/core/lib/Drupal/Core/Form/FormAlter.php @@ -48,9 +48,10 @@ public function __construct(ModuleHandlerInterface $module_handler, ThemeManager public function alterForm($form_id, &$form, FormStateInterface $form_state) { // Invoke hook_form_alter(), hook_form_BASE_FORM_ID_alter(), and // hook_form_FORM_ID_alter() implementations. - $hooks = array('form'); - if (isset($form_state['build_info']['base_form_id'])) { - $hooks[] = 'form_' . $form_state['build_info']['base_form_id']; + $hooks = ['form']; + $build_info = $form_state->getBuildInfo(); + if (isset($build_info['base_form_id'])) { + $hooks[] = 'form_' . $build_info['base_form_id']; } $hooks[] = 'form_' . $form_id; $this->moduleHandler->alter($hooks, $form, $form_state, $form_id); diff --git a/core/tests/Drupal/Tests/Core/Form/FormAlterTest.php b/core/tests/Drupal/Tests/Core/Form/FormAlterTest.php index 5e61445..907c7f0 100644 --- a/core/tests/Drupal/Tests/Core/Form/FormAlterTest.php +++ b/core/tests/Drupal/Tests/Core/Form/FormAlterTest.php @@ -56,7 +56,7 @@ protected function setUp() { */ public function testAlterForm($form_id, $expected_hooks, $form_state_additions = []) { $form = []; - $form_state = new FormState($form_state_additions); + $form_state = (new FormState())->setFormState($form_state_additions); $this->moduleHandler->expects($this->once()) ->method('alter') @@ -73,14 +73,14 @@ public function testAlterForm($form_id, $expected_hooks, $form_state_additions = */ public function providerTestAlterForm() { $data = []; - $data[] = [ + $data['no_build_info'] = [ 'red', [ 'form', 'form_red', ], ]; - $data[] = [ + $data['with_build_info'] = [ 'red', [ 'form', diff --git a/core/tests/Drupal/Tests/Core/Form/FormTestBase.php b/core/tests/Drupal/Tests/Core/Form/FormTestBase.php index c91a11e..612b35d 100644 --- a/core/tests/Drupal/Tests/Core/Form/FormTestBase.php +++ b/core/tests/Drupal/Tests/Core/Form/FormTestBase.php @@ -140,6 +140,8 @@ * {@inheritdoc} */ protected function setUp() { + parent::setUp(); + $this->formCache = $this->getMock('Drupal\Core\Form\FormCacheInterface'); $this->formAlter = $this->getMock('Drupal\Core\Form\FormAlterInterface'); $this->urlGenerator = $this->getMock('Drupal\Core\Routing\UrlGeneratorInterface');