From a2facd2f1bbe95eeeeec0a51fd24f86ce5f9ddbc Mon Sep 17 00:00:00 2001 From: webchick Date: Mon, 8 Sep 2014 09:01:19 -0700 Subject: [PATCH] Issue #2333353 by ashutoshsngh: Remove usage of form_get_errors(). --- core/lib/Drupal/Core/Block/BlockBase.php | 2 +- core/lib/Drupal/Core/Form/FormBuilderInterface.php | 2 +- core/modules/comment/comment.module | 2 +- core/modules/datetime/datetime.module | 4 ++-- core/modules/editor/src/Form/EditorImageDialog.php | 2 +- core/modules/editor/src/Form/EditorLinkDialog.php | 2 +- core/modules/node/src/NodeForm.php | 2 +- .../modules/system/src/Tests/Form/ElementsTableSelectTest.php | 3 ++- core/modules/system/src/Tests/Form/FormTest.php | 4 ++-- core/modules/system/src/Tests/Form/ProgrammaticTest.php | 2 +- .../system/src/Tests/System/SystemConfigFormTestBase.php | 2 +- core/modules/taxonomy/src/Form/OverviewTerms.php | 2 +- core/modules/views_ui/src/Form/Ajax/ConfigHandler.php | 2 +- core/modules/views_ui/src/Form/Ajax/Display.php | 2 +- 14 files changed, 17 insertions(+), 16 deletions(-) diff --git a/core/lib/Drupal/Core/Block/BlockBase.php b/core/lib/Drupal/Core/Block/BlockBase.php index ed2a63abb306..7d66cf4cac0d 100644 --- a/core/lib/Drupal/Core/Block/BlockBase.php +++ b/core/lib/Drupal/Core/Block/BlockBase.php @@ -382,7 +382,7 @@ abstract class BlockBase extends ContextAwarePluginBase implements BlockPluginIn */ public function submitConfigurationForm(array &$form, FormStateInterface $form_state) { // Process the block's submission handling if no errors occurred only. - if (!form_get_errors($form_state)) { + if (!$form_state->getErrors()) { $this->configuration['label'] = $form_state->getValue('label'); $this->configuration['label_display'] = $form_state->getValue('label_display'); $this->configuration['provider'] = $form_state->getValue('provider'); diff --git a/core/lib/Drupal/Core/Form/FormBuilderInterface.php b/core/lib/Drupal/Core/Form/FormBuilderInterface.php index 3f16f50e653c..3e97b495e867 100644 --- a/core/lib/Drupal/Core/Form/FormBuilderInterface.php +++ b/core/lib/Drupal/Core/Form/FormBuilderInterface.php @@ -119,7 +119,7 @@ interface FormBuilderInterface { * processes a form, but does not allow you to supply values. * * There is no return value, but you can check to see if there are errors - * by calling form_get_errors(). + * by calling $form_state->getErrors(). * * @param \Drupal\Core\Form\FormInterface|string $form_arg * A form object to use to build the form, or the unique string identifying diff --git a/core/modules/comment/comment.module b/core/modules/comment/comment.module index 5f6f906c9337..dbe3bee462f3 100644 --- a/core/modules/comment/comment.module +++ b/core/modules/comment/comment.module @@ -613,7 +613,7 @@ function comment_preview(CommentInterface $comment, FormStateInterface $form_sta $preview_build = array(); $entity = $comment->getCommentedEntity(); - if (!form_get_errors($form_state)) { + if (!$form_state->getErrors()) { // Attach the user and time information. $author_name = $comment->getAuthorName(); if (!empty($author_name)) { diff --git a/core/modules/datetime/datetime.module b/core/modules/datetime/datetime.module index cca729f69b72..ffae4f503c35 100644 --- a/core/modules/datetime/datetime.module +++ b/core/modules/datetime/datetime.module @@ -61,7 +61,7 @@ function datetime_help($route_name, RouteMatchInterface $route_match) { * The current state of the form. */ function datetime_datetime_widget_validate(&$element, FormStateInterface $form_state) { - if (!form_get_errors($form_state)) { + if (!$form_state->getErrors()) { $input_exists = FALSE; $input = NestedArray::getValue($form_state->getValues(), $element['#parents'], $input_exists); if ($input_exists) { @@ -99,7 +99,7 @@ function datetime_datetime_widget_validate(&$element, FormStateInterface $form_s * The current state of the form. */ function datetime_datelist_widget_validate(&$element, FormStateInterface $form_state) { - if (!form_get_errors($form_state)) { + if (!$form_state->getErrors()) { $input_exists = FALSE; $input = NestedArray::getValue($form_state->getValues(), $element['#parents'], $input_exists); if ($input_exists) { diff --git a/core/modules/editor/src/Form/EditorImageDialog.php b/core/modules/editor/src/Form/EditorImageDialog.php index ddcebb3a1426..342f28381f5a 100644 --- a/core/modules/editor/src/Form/EditorImageDialog.php +++ b/core/modules/editor/src/Form/EditorImageDialog.php @@ -223,7 +223,7 @@ class EditorImageDialog extends FormBase { $form_state->setValue(array('attributes', 'alt'), ''); } - if (form_get_errors($form_state)) { + if ($form_state->getErrors()) { unset($form['#prefix'], $form['#suffix']); $status_messages = array('#theme' => 'status_messages'); $output = drupal_render($form); diff --git a/core/modules/editor/src/Form/EditorLinkDialog.php b/core/modules/editor/src/Form/EditorLinkDialog.php index 758b489d14cf..29ce81215962 100644 --- a/core/modules/editor/src/Form/EditorLinkDialog.php +++ b/core/modules/editor/src/Form/EditorLinkDialog.php @@ -83,7 +83,7 @@ class EditorLinkDialog extends FormBase { public function submitForm(array &$form, FormStateInterface $form_state) { $response = new AjaxResponse(); - if (form_get_errors($form_state)) { + if ($form_state->getErrors()) { unset($form['#prefix'], $form['#suffix']); $status_messages = array('#theme' => 'status_messages'); $output = drupal_render($form); diff --git a/core/modules/node/src/NodeForm.php b/core/modules/node/src/NodeForm.php index 5bf0506c6d7a..4cf7edd9de95 100644 --- a/core/modules/node/src/NodeForm.php +++ b/core/modules/node/src/NodeForm.php @@ -260,7 +260,7 @@ class NodeForm extends ContentEntityForm { $node = $this->entity; $preview_mode = $this->settings['preview']; - $element['submit']['#access'] = $preview_mode != DRUPAL_REQUIRED || (!form_get_errors($form_state) && isset($form_state['node_preview'])); + $element['submit']['#access'] = $preview_mode != DRUPAL_REQUIRED || (!$form_state->getErrors() && isset($form_state['node_preview'])); // If saving is an option, privileged users get dedicated form submit // buttons to adjust the publishing status while saving in one go. diff --git a/core/modules/system/src/Tests/Form/ElementsTableSelectTest.php b/core/modules/system/src/Tests/Form/ElementsTableSelectTest.php index cd6ba3199939..0bde8d0daf6e 100644 --- a/core/modules/system/src/Tests/Form/ElementsTableSelectTest.php +++ b/core/modules/system/src/Tests/Form/ElementsTableSelectTest.php @@ -9,6 +9,7 @@ namespace Drupal\system\Tests\Form; use Drupal\Core\Form\FormState; use Drupal\simpletest\WebTestBase; +use Drupal\Core\Form\FormStateInterface; /** * Tests the tableselect form element for expected behavior. @@ -223,7 +224,7 @@ class ElementsTableSelectTest extends WebTestBase { drupal_process_form($form_id, $form, $form_state); - $errors = form_get_errors($form_state); + $errors = $form_state->getErrors(); // Clear errors and messages. drupal_get_messages(); diff --git a/core/modules/system/src/Tests/Form/FormTest.php b/core/modules/system/src/Tests/Form/FormTest.php index 31481c9ac27f..be8d7e04e291 100644 --- a/core/modules/system/src/Tests/Form/FormTest.php +++ b/core/modules/system/src/Tests/Form/FormTest.php @@ -47,7 +47,7 @@ class FormTest extends WebTestBase { * Carriage returns, tabs, spaces, and unchecked checkbox elements are not * valid content for a required field. * - * If the form field is found in form_get_errors() then the test pass. + * If the form field is found in $form_state->getErrors() then the test pass. */ function testRequiredFields() { // Originates from http://drupal.org/node/117748 @@ -118,7 +118,7 @@ class FormTest extends WebTestBase { $form['#token'] = FALSE; \Drupal::formBuilder()->prepareForm($form_id, $form, $form_state); drupal_process_form($form_id, $form, $form_state); - $errors = form_get_errors($form_state); + $errors = $form_state->getErrors(); // Form elements of type 'radios' throw all sorts of PHP notices // when you try to render them like this, so we ignore those for // testing the required marker. diff --git a/core/modules/system/src/Tests/Form/ProgrammaticTest.php b/core/modules/system/src/Tests/Form/ProgrammaticTest.php index 16c11b36ae09..cfe9cb232d30 100644 --- a/core/modules/system/src/Tests/Form/ProgrammaticTest.php +++ b/core/modules/system/src/Tests/Form/ProgrammaticTest.php @@ -76,7 +76,7 @@ class ProgrammaticTest extends WebTestBase { \Drupal::formBuilder()->submitForm('\Drupal\form_test\Form\FormTestProgrammaticForm', $form_state); // Check that the form returns an error when expected, and vice versa. - $errors = form_get_errors($form_state); + $errors = $form_state->getErrors(); $valid_form = empty($errors); $args = array( '%values' => print_r($values, TRUE), diff --git a/core/modules/system/src/Tests/System/SystemConfigFormTestBase.php b/core/modules/system/src/Tests/System/SystemConfigFormTestBase.php index cabd86315919..388977ac43f3 100644 --- a/core/modules/system/src/Tests/System/SystemConfigFormTestBase.php +++ b/core/modules/system/src/Tests/System/SystemConfigFormTestBase.php @@ -56,7 +56,7 @@ abstract class SystemConfigFormTestBase extends WebTestBase { \Drupal::formBuilder()->submitForm($this->form, $form_state); // Check that the form returns an error when expected, and vice versa. - $errors = form_get_errors($form_state); + $errors = $form_state->getErrors(); $valid_form = empty($errors); $args = array( '%values' => print_r($values, TRUE), diff --git a/core/modules/taxonomy/src/Form/OverviewTerms.php b/core/modules/taxonomy/src/Form/OverviewTerms.php index e2eeef0cfc21..f94d728fdbf6 100644 --- a/core/modules/taxonomy/src/Form/OverviewTerms.php +++ b/core/modules/taxonomy/src/Form/OverviewTerms.php @@ -189,7 +189,7 @@ class OverviewTerms extends FormBase { } } - $errors = form_get_errors($form_state); + $errors = $form_state->getErrors(); $destination = drupal_get_destination(); $row_position = 0; // Build the actual form. diff --git a/core/modules/views_ui/src/Form/Ajax/ConfigHandler.php b/core/modules/views_ui/src/Form/Ajax/ConfigHandler.php index 9c100bc6de6d..02fb02f0ee29 100644 --- a/core/modules/views_ui/src/Form/Ajax/ConfigHandler.php +++ b/core/modules/views_ui/src/Form/Ajax/ConfigHandler.php @@ -193,7 +193,7 @@ class ConfigHandler extends ViewsFormBase { public function validateForm(array &$form, FormStateInterface $form_state) { $form_state['handler']->validateOptionsForm($form['options'], $form_state); - if (form_get_errors($form_state)) { + if ($form_state->getErrors()) { $form_state['rerender'] = TRUE; } } diff --git a/core/modules/views_ui/src/Form/Ajax/Display.php b/core/modules/views_ui/src/Form/Ajax/Display.php index c653fc1763af..7ac9832de717 100644 --- a/core/modules/views_ui/src/Form/Ajax/Display.php +++ b/core/modules/views_ui/src/Form/Ajax/Display.php @@ -99,7 +99,7 @@ class Display extends ViewsFormBase { public function validateForm(array &$form, FormStateInterface $form_state) { $form_state['view']->getExecutable()->displayHandlers->get($form_state['display_id'])->validateOptionsForm($form['options'], $form_state); - if (form_get_errors($form_state)) { + if ($form_state->getErrors()) { $form_state['rerender'] = TRUE; } }