Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
ui_suite_bootstrap
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
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
project
ui_suite_bootstrap
Merge requests
!94
Issue
#3352946
: Get forms are always validated
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Issue
#3352946
: Get forms are always validated
issue/ui_suite_bootstrap-3352946:3352946-get-forms-are
into
5.0.x
Overview
0
Commits
2
Pipelines
0
Changes
3
Merged
Florent Torregrosa
requested to merge
issue/ui_suite_bootstrap-3352946:3352946-get-forms-are
into
5.0.x
2 years ago
Overview
0
Commits
2
Pipelines
0
Changes
3
Expand
0
0
Merge request reports
Compare
5.0.x
version 1
6a1752cc
2 years ago
5.0.x (base)
and
latest version
latest version
8dd035f2
2 commits,
2 years ago
version 1
6a1752cc
1 commit,
2 years ago
3 files
+
77
−
2
Side-by-side
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
3
Search (e.g. *.vue) (Ctrl+P)
src/HookHandler/FormAlter.php
0 → 100644
+
60
−
0
Options
<?php
declare
(
strict_types
=
1
);
namespace
Drupal\ui_suite_bootstrap\HookHandler
;
use
Drupal\Core\Form\FormStateInterface
;
use
Drupal\Core\Render\Element
;
/**
* Alter forms.
*/
class
FormAlter
{
/**
* Alter forms.
*
* @param array $form
* The form structure.
* @param \Drupal\Core\Form\FormStateInterface $formState
* The form state.
* @param string $form_id
* The form ID.
*/
public
function
alter
(
array
&
$form
,
FormStateInterface
$formState
,
string
$form_id
):
void
{
// See \Drupal\Core\Form\FormBuilder::processForm().
if
(
$formState
->
isMethodType
(
'get'
)
&&
$formState
->
getAlwaysProcess
())
{
$form
[
'#after_build'
][]
=
[
static
::
class
,
'afterBuildAddGetFormMethod'
,
];
}
}
/**
* Form element #after_build callback.
*/
public
static
function
afterBuildAddGetFormMethod
(
array
$element
,
FormStateInterface
$form_state
):
array
{
static
::
addGetFormMethod
(
$element
);
return
$element
;
}
/**
* Set form method to all form elements.
*
* To allow other processing to act based on this information.
*
* @param array $form
* The form or form element which children should have form method attached.
*/
protected
static
function
addGetFormMethod
(
array
&
$form
):
void
{
foreach
(
Element
::
children
(
$form
)
as
$child
)
{
if
(
!
isset
(
$form
[
$child
][
'#form_method'
]))
{
$form
[
$child
][
'#form_method'
]
=
'get'
;
}
static
::
addGetFormMethod
(
$form
[
$child
]);
}
}
}
Loading