Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
ui_patterns
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_patterns
Commits
e6a1e80d
Commit
e6a1e80d
authored
2 months ago
by
Mikael Meulle
Committed by
Pierre Dureau
2 months ago
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3488044
by just_like_good_vibes: Fix 'submitted value is not allowed' in component prop form
parent
78aba575
No related branches found
No related tags found
1 merge request
!266
Issue #3488044 by just_like_good_vibes: Fix 'submitted value is not allowed' in component prop form
Pipeline
#345280
passed
2 months ago
Stage: build
Stage: validate
Stage: test
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/Plugin/UiPatterns/Source/DerivableContextSourceBase.php
+36
-2
36 additions, 2 deletions
src/Plugin/UiPatterns/Source/DerivableContextSourceBase.php
with
36 additions
and
2 deletions
src/Plugin/UiPatterns/Source/DerivableContextSourceBase.php
+
36
−
2
View file @
e6a1e80d
...
...
@@ -173,7 +173,6 @@ abstract class DerivableContextSourceBase extends SourcePluginBase {
private
function
buildDerivableContextSelectorForm
(
array
&
$form
,
FormStateInterface
$form_state
)
:
array
{
$derivableContexts
=
$this
->
listCompatibleDerivableContexts
();
$wrapper_id
=
Html
::
getId
(
implode
(
"_"
,
$this
->
formArrayParents
??
[])
.
"_derivable_context_selector"
);
$derivable_context
=
(
string
)
(
$this
->
getSetting
(
'derivable_context'
)
??
''
);
$options_derivable_contexts
=
$this
->
getDerivableContextsOptions
(
$derivableContexts
);
$form
=
[
'#type'
=>
'container'
,
...
...
@@ -185,12 +184,12 @@ abstract class DerivableContextSourceBase extends SourcePluginBase {
];
return
$form
;
}
$derivable_context
=
$this
->
getSelectedDerivableContext
(
$form_state
,
$options_derivable_contexts
);
$form
[
"derivable_context"
]
=
[
"#type"
=>
"select"
,
"#title"
=>
$this
->
t
(
"Context"
),
"#options"
=>
$options_derivable_contexts
,
'#default_value'
=>
$derivable_context
,
'#ajax'
=>
[
'callback'
=>
[
__CLASS__
,
'onDerivableContextChange'
],
'wrapper'
=>
$wrapper_id
,
...
...
@@ -247,6 +246,41 @@ abstract class DerivableContextSourceBase extends SourcePluginBase {
return
$form
;
}
/**
* Get the selected derivable context and validate it.
*
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The form state.
* @param array<string, mixed> $options_derivable_contexts
* The options.
*
* @return string|null
* The selected and validated derivable context.
*/
private
function
getSelectedDerivableContext
(
FormStateInterface
$form_state
,
array
$options_derivable_contexts
)
:
?string
{
$derivable_context
=
(
string
)
(
$this
->
getSetting
(
'derivable_context'
)
??
''
);
// Validate the selected derivable context.
if
(
$derivable_context
&&
!
isset
(
$options_derivable_contexts
[
$derivable_context
]))
{
// Reset value, or take the first one if only one is available.
$derivable_context
=
(
count
(
$options_derivable_contexts
)
===
1
)
?
key
(
$options_derivable_contexts
)
:
NULL
;
// Clean up the input if needed
// Covers ComponentPropForm::switchSourceForm() AJAX handler.
if
(
$form_state
->
isProcessingInput
())
{
$complete_form
=
$form_state
->
getCompleteForm
();
$prop_form
=
NestedArray
::
getValue
(
$complete_form
,
$this
->
formArrayParents
);
$input
=
$form_state
->
getUserInput
();
$prop_input
=
&
NestedArray
::
getValue
(
$input
,
$prop_form
[
"#parents"
]);
if
(
isset
(
$prop_input
[
"source"
]))
{
unset
(
$prop_input
[
"source"
]);
// Reset the user input, form state values
// will be recomputed by FormBuilder.
$form_state
->
setUserInput
(
$input
);
}
}
}
return
$derivable_context
;
}
/**
* Get derivable contexts options.
*
...
...
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