diff --git a/core/lib/Drupal/Core/Entity/EntityForm.php b/core/lib/Drupal/Core/Entity/EntityForm.php index 30d8aa2..cec828a 100644 --- a/core/lib/Drupal/Core/Entity/EntityForm.php +++ b/core/lib/Drupal/Core/Entity/EntityForm.php @@ -231,6 +231,15 @@ protected function actions(array $form, FormStateInterface $form_state) { * {@inheritdoc} */ public function validate(array &$form, FormStateInterface $form_state) { + $validate_handlers = $form_state->getValidateHandlers(); + // Remove this method from the list of validate handlers. + unset($validate_handlers[array_search('::validate', $validate_handlers)]); + // If there are no other validate handlers, make sure the form-level + // validate handler runs. + if (count($validate_handlers) === 0) { + $form_state->setValidateHandlers([]); + \Drupal::service('form_validator')->executeValidateHandlers($form, $form_state); + } } /** diff --git a/core/modules/system/src/Tests/Entity/EntityFormTest.php b/core/modules/system/src/Tests/Entity/EntityFormTest.php index dcdb20f..ffb72aa 100644 --- a/core/modules/system/src/Tests/Entity/EntityFormTest.php +++ b/core/modules/system/src/Tests/Entity/EntityFormTest.php @@ -66,7 +66,8 @@ protected function doTestFormCRUD($entity_type) { ); $this->drupalPostForm($entity_type . '/add', $edit, t('Save')); - $this->assertNoRaw('This should not run.'); + $this->assertNoRaw('This method should not run.'); + $this->assertRaw('This method should run.'); $entity = $this->loadEntityByName($entity_type, $name1); $this->assertTrue($entity, format_string('%entity_type: Entity found in the database.', array('%entity_type' => $entity_type))); diff --git a/core/modules/system/tests/modules/entity_test/src/EntityTestForm.php b/core/modules/system/tests/modules/entity_test/src/EntityTestForm.php index 0f13979..29c7d8b 100644 --- a/core/modules/system/tests/modules/entity_test/src/EntityTestForm.php +++ b/core/modules/system/tests/modules/entity_test/src/EntityTestForm.php @@ -51,8 +51,24 @@ public function form(array $form, FormStateInterface $form_state) { /** * {@inheritdoc} */ + protected function actions(array $form, FormStateInterface $form_state) { + $actions = parent::actions($form, $form_state); + $actions['submit']['#validate'][] = '::buttonLevelValidator'; + return $actions; + } + + /** + * {@inheritdoc} + */ public function formLevelValidator(array &$form, FormStateInterface $form_state) { - $form_state->setError($form, 'This should not run.'); + $form_state->setError($form, 'This method should not run.'); + } + + /** + * {@inheritdoc} + */ + public function buttonLevelValidator(array &$form, FormStateInterface $form_state) { + drupal_set_message('This method should run.'); } /**