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
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
ui_patterns
Merge requests
!99
Issue
#3447833
by mogtofu33: Feature for dev, better ComponentValidator
Code
Review changes
Check out branch
Open in Workspace
Download
Patches
Plain diff
Expand sidebar
Merged
Issue
#3447833
by mogtofu33: Feature for dev, better ComponentValidator
issue/ui_patterns-3447833:3447833-feature-for-dev
into
2.0.x
Overview
0
Commits
1
Pipelines
0
Changes
4
Merged
Issue #3447833 by mogtofu33: Feature for dev, better ComponentValidator
Jean Valverde
requested to merge
issue/ui_patterns-3447833:3447833-feature-for-dev
into
2.0.x
May 17, 2024
Overview
0
Commits
1
Pipelines
0
Changes
4
Closes
#3447833
0
0
Merge request reports
Compare
2.0.x
version 2
6b270b36
May 23, 2024
version 1
2bb9d277
May 17, 2024
2.0.x (base)
and
latest version
latest version
dfa01fe8
1 commit,
May 27, 2024
version 2
6b270b36
1 commit,
May 23, 2024
version 1
2bb9d277
1 commit,
May 17, 2024
4 files
+
113
−
0
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
4
modules/ui_patterns_devel/src/Component/ComponentValidator.php
0 → 100644
+
64
−
0
View file @ dfa01fe8
Edit in single-file editor
Open in Web IDE
<?php
declare
(
strict_types
=
1
);
namespace
Drupal\ui_patterns_devel\Component
;
use
Drupal\Core\Plugin\Component
;
use
Drupal\Core\Render\Component\Exception\InvalidComponentException
;
use
Drupal\Core\Theme\Component\ComponentValidator
as
OriginalComponentValidator
;
/**
* Override validation of a component.
*/
final
class
ComponentValidator
extends
OriginalComponentValidator
{
/**
* Override the component metadata validation to always pass.
*
* @param array $definition
* The definition to validate.
* @param bool $enforce_schemas
* TRUE if schema definitions are mandatory.
*
* @return bool
* Always TRUE to display the error as a message.
*/
public
function
validateDefinition
(
array
$definition
,
bool
$enforce_schemas
):
bool
{
try
{
parent
::
validateDefinition
(
$definition
,
$enforce_schemas
);
}
catch
(
InvalidComponentException
$e
)
{
$component_id
=
$definition
[
'id'
];
$message
=
\str_replace
(
"/n"
,
"<br>"
,
$e
->
getMessage
());
\Drupal
::
messenger
()
->
addError
(
\sprintf
(
"Component: <b>%s</b><br>%s"
,
$component_id
,
$message
));
}
return
TRUE
;
}
/**
* Override the props provided to the component to always pass.
*
* @param array $context
* The Twig context that contains the prop data.
* @param \Drupal\Core\Plugin\Component $component
* The component to validate the props against.
*
* @return bool
* Always TRUE to display the error as a message.
*/
public
function
validateProps
(
array
$context
,
Component
$component
):
bool
{
try
{
parent
::
validateProps
(
$context
,
$component
);
}
catch
(
InvalidComponentException
$e
)
{
$component_id
=
$component
->
getPluginId
();
$message
=
\str_replace
(
"/n"
,
"<br>"
,
$e
->
getMessage
());
\Drupal
::
messenger
()
->
addError
(
\sprintf
(
"Component: <b>%s</b><br>%s"
,
$component_id
,
$message
));
}
return
TRUE
;
}
}
Loading