Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
drupal-3174996
Manage
Activity
Members
Labels
Plan
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Issue forks
drupal-3174996
Commits
b774fcbf
Commit
b774fcbf
authored
12 years ago
by
Daniel Wehner
Committed by
Tim Plunkett
12 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#1760276
by dawehner: Improve wizard validation related methods.
parent
9fc9f6f8
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lib/Drupal/views/Plugin/views/wizard/WizardInterface.php
+18
-5
18 additions, 5 deletions
lib/Drupal/views/Plugin/views/wizard/WizardInterface.php
lib/Drupal/views/Plugin/views/wizard/WizardPluginBase.php
+24
-15
24 additions, 15 deletions
lib/Drupal/views/Plugin/views/wizard/WizardPluginBase.php
with
42 additions
and
20 deletions
lib/Drupal/views/Plugin/views/wizard/WizardInterface.php
+
18
−
5
View file @
b774fcbf
...
...
@@ -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
);
}
This diff is collapsed.
Click to expand it.
lib/Drupal/views/Plugin/views/wizard/WizardPluginBase.php
+
24
−
15
View file @
b774fcbf
...
...
@@ -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
;
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment