From b774fcbf5fc6b77451c2945099c700bd4917a4b0 Mon Sep 17 00:00:00 2001
From: dereine <dereine@99340.no-reply.drupal.org>
Date: Wed, 29 Aug 2012 19:54:17 +0200
Subject: [PATCH] Issue #1760276 by dawehner: Improve wizard validation related
 methods.

---
 .../Plugin/views/wizard/WizardInterface.php   | 23 ++++++++---
 .../Plugin/views/wizard/WizardPluginBase.php  | 39 ++++++++++++-------
 2 files changed, 42 insertions(+), 20 deletions(-)

diff --git a/lib/Drupal/views/Plugin/views/wizard/WizardInterface.php b/lib/Drupal/views/Plugin/views/wizard/WizardInterface.php
index 70899c80b074..f736ba292166 100644
--- a/lib/Drupal/views/Plugin/views/wizard/WizardInterface.php
+++ b/lib/Drupal/views/Plugin/views/wizard/WizardInterface.php
@@ -28,17 +28,30 @@ function build_form($form, &$form_state);
   /**
    * Validate form and values.
    *
-   * @return an array of form errors.
+   * @param array $form
+   *   The full wizard form array.
+   * @param array $form_state
+   *   The current state of the wizard form.
+   *
+   * @return array
+   *   An empty array if the view is valid; an array of error strings if it is
+   *   not.
    */
-  function validate($form, &$form_state);
+  function validate(array $form, array &$form_state);
 
   /**
-   * Create a new View from form values.
+   * Creates a view from values that have already been validated.
+   *
+   * @param array $form
+   *   The full wizard form array.
+   * @param array $form_state
+   *   The current state of the wizard form.
    *
-   * @return a view object.
+   * @return Drupal\views\View
+   *   The created view object.
    *
    * @throws Drupal\views\Plugin\views\wizard\WizardException
    */
-  function create_view($form, &$form_state);
+  function create_view(array $form, array &$form_state);
 
 }
diff --git a/lib/Drupal/views/Plugin/views/wizard/WizardPluginBase.php b/lib/Drupal/views/Plugin/views/wizard/WizardPluginBase.php
index 22c128b0d7d6..9dd96fa3326c 100644
--- a/lib/Drupal/views/Plugin/views/wizard/WizardPluginBase.php
+++ b/lib/Drupal/views/Plugin/views/wizard/WizardPluginBase.php
@@ -944,8 +944,20 @@ protected function set_override_options($options, $display, $default_display) {
 
   /**
    * Retrieves a validated view for a form submission.
+   *
+   * @param array $form
+   *   The full wizard form array.
+   * @param array $form_state
+   *   The current state of the wizard form.
+   * @param bool $unset
+   *   Should the view be removed from the list of validated views.
+   *
+   * @return Drupal\views\View $view
+   *   The validated view object.
    */
-  protected function retrieve_validated_view($form, $form_state, $unset = TRUE) {
+  protected function retrieve_validated_view(array $form, array &$form_state, $unset = TRUE) {
+    // @todo Figure out why all this hashing is done. Wouldn't it be easier to
+    //   store a single entry and that's it?
     $key = hash('sha256', serialize($form_state['values']));
     $view = (isset($this->validated_views[$key]) ? $this->validated_views[$key] : NULL);
     if ($unset) {
@@ -956,8 +968,15 @@ protected function retrieve_validated_view($form, $form_state, $unset = TRUE) {
 
   /**
    * Stores a validated view from a form submission.
+   *
+   * @param array $form
+   *   The full wizard form array.
+   * @param array $form_state
+   *   The current state of the wizard form.
+   * @param Drupal\views\View $view
+   *   The validated view object.
    */
-  protected function set_validated_view($form, $form_state, $view) {
+  protected function set_validated_view(array $form, array &$form_state, View $view) {
     $key = hash('sha256', serialize($form_state['values']));
     $this->validated_views[$key] = $view;
   }
@@ -966,11 +985,8 @@ protected function set_validated_view($form, $form_state, $view) {
    * Implements Drupal\views\Plugin\views\wizard\WizardInterface::validate().
    *
    * Instantiates the view from the form submission and validates its values.
-   *
-   * @return
-   *   TRUE if the view is valid; an array of error strings if it is not.
    */
-  function validate($form, &$form_state) {
+  function validate(array $form, array &$form_state) {
     $view = $this->instantiate_view($form, $form_state);
     $errors = $view->validate();
     if (!is_array($errors) || empty($errors)) {
@@ -982,18 +998,11 @@ function validate($form, &$form_state) {
 
   /**
    * Implements Drupal\views\Plugin\views\wizard\WizardInterface::create_view().
-   *
-   * Creates a view from values that have already been validated.
-   *
-   * @return
-   *   The created view object.
-   *
-   * @throws Drupal\views\Plugin\views\wizard\WizardException
    */
-  function create_view($form, &$form_state) {
+  function create_view(array $form, array &$form_state) {
     $view = $this->retrieve_validated_view($form, $form_state);
     if (empty($view)) {
-      throw new WizardException(t('Attempted to create_view with values that have not been validated'));
+      throw new WizardException('Attempted to create_view with values that have not been validated.');
     }
     return $view;
   }
-- 
GitLab