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
98575928
Commit
98575928
authored
7 months ago
by
christian.wiedemann
Committed by
Mikael Meulle
7 months ago
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3473344
by christian.wiedemann: Validate Layout before saving the layout
parent
8b68b153
No related branches found
No related tags found
1 merge request
!197
Resolve #3473344 "2.0.0 beta2 validate layout"
Pipeline
#281896
passed with warnings
7 months ago
Stage: build
Stage: validate
Stage: test
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
modules/ui_patterns_layouts/src/Plugin/Layout/ComponentLayout.php
+2
-8
2 additions, 8 deletions
...ui_patterns_layouts/src/Plugin/Layout/ComponentLayout.php
src/Element/ComponentForm.php
+31
-6
31 additions, 6 deletions
src/Element/ComponentForm.php
with
33 additions
and
14 deletions
modules/ui_patterns_layouts/src/Plugin/Layout/ComponentLayout.php
+
2
−
8
View file @
98575928
...
...
@@ -48,7 +48,7 @@ class ComponentLayout extends LayoutDefault implements ContainerFactoryPluginInt
* @param mixed $plugin_definition
* The plugin implementation definition.
* @param \Drupal\ui_patterns\Resolver\ChainContextEntityResolverInterface $chainContextEntityResolver
* The context
help
er.
* The context
resolv
er.
*/
public
function
__construct
(
array
$configuration
,
...
...
@@ -67,7 +67,7 @@ class ComponentLayout extends LayoutDefault implements ContainerFactoryPluginInt
$configuration
,
$plugin_id
,
$plugin_definition
,
$container
->
get
(
'ui_patterns.chain_context_entity_resolver'
)
$container
->
get
(
'ui_patterns.chain_context_entity_resolver'
)
,
);
return
$plugin
;
}
...
...
@@ -152,12 +152,6 @@ class ComponentLayout extends LayoutDefault implements ContainerFactoryPluginInt
return
$form
;
}
/**
* {@inheritdoc}
*/
public
function
validateConfigurationForm
(
array
&
$form
,
FormStateInterface
$form_state
)
:
void
{
}
/**
* {@inheritdoc}
*/
...
...
This diff is collapsed.
Click to expand it.
src/Element/ComponentForm.php
+
31
−
6
View file @
98575928
...
...
@@ -6,6 +6,7 @@ use Drupal\Component\Utility\NestedArray;
use
Drupal\Core\Form\FormStateInterface
;
use
Drupal\Core\Plugin\Context\Context
;
use
Drupal\Core\Plugin\Context\ContextDefinition
;
use
Drupal\Core\Render\RenderContext
;
/**
* Provides a Component form builder element.
...
...
@@ -116,7 +117,7 @@ class ComponentForm extends ComponentFormBase {
$component_selector_form
=
array_merge
(
self
::
buildComponentSelectorForm
(
$wrapper_id
,
$component_id
),
[
"#ajax_url"
=>
$element
[
"#ajax_url"
]]);
),
[
"#ajax_url"
=>
$element
[
"#ajax_url"
]
??
NULL
]);
$element
[
"component_id"
]
=
self
::
expandAjax
(
$component_selector_form
);
}
self
::
buildComponentForm
(
...
...
@@ -223,7 +224,7 @@ class ComponentForm extends ComponentFormBase {
'#component_id'
=>
$component_id
,
'#source_contexts'
=>
$element
[
'#source_contexts'
],
'#tag_filter'
=>
$element
[
'#tag_filter'
],
'#ajax_url'
=>
$element
[
'#ajax_url'
],
'#ajax_url'
=>
$element
[
'#ajax_url'
]
??
NULL
,
'#access'
=>
$element
[
'#render_slots'
]
??
TRUE
,
'#default_value'
=>
[
'slots'
=>
$element
[
'#default_value'
][
'slots'
],
...
...
@@ -241,7 +242,7 @@ class ComponentForm extends ComponentFormBase {
'#component_id'
=>
$component_id
,
'#source_contexts'
=>
$element
[
'#source_contexts'
],
'#tag_filter'
=>
$element
[
'#tag_filter'
],
'#ajax_url'
=>
$element
[
'#ajax_url'
],
'#ajax_url'
=>
$element
[
'#ajax_url'
]
??
NULL
,
'#access'
=>
$element
[
'#render_props'
]
??
TRUE
,
'#default_value'
=>
[
'props'
=>
$element
[
'#default_value'
][
'props'
],
...
...
@@ -266,9 +267,33 @@ class ComponentForm extends ComponentFormBase {
* Form element validation handler.
*/
public
static
function
validateFormElement
(
array
&
$element
,
FormStateInterface
$form_state
)
:
void
{
$trigger_element
=
$form_state
->
getTriggeringElement
();
if
(
isset
(
$trigger_element
[
'#ui_patterns'
])
===
FALSE
)
{
$form_state
->
setValueForElement
(
$element
,
$element
[
'#value'
]);
try
{
$trigger_element
=
$form_state
->
getTriggeringElement
();
if
(
isset
(
$trigger_element
[
'#ui_patterns'
])
===
FALSE
)
{
$build
=
[
'#type'
=>
'component'
,
'#component'
=>
$element
[
'#value'
][
'component_id'
]
??
$element
[
'#component_id'
],
'#ui_patterns'
=>
$element
[
'#value'
],
'#source_contexts'
=>
$element
[
'#source_contexts'
]
??
[],
];
$context
=
new
RenderContext
();
$renderer
=
\Drupal
::
service
(
"renderer"
);
$renderer
->
executeInRenderContext
(
$context
,
function
()
use
(
&
$build
,
$renderer
)
{
return
$renderer
->
render
(
$build
);
});
$form_state
->
setValueForElement
(
$element
,
$element
[
'#value'
]);
}
}
catch
(
\Throwable
$e
)
{
// If a component_id is we just show the error message instead
// of highlighting the whole form.
if
(
!
empty
(
$element
[
'#component_id'
]))
{
$form_state
->
setErrorByName
(
''
,
$e
->
getMessage
());
}
else
{
$form_state
->
setError
(
$element
[
'component_id'
],
$e
->
getMessage
());
}
}
}
...
...
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