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
Merge requests
!358
Issue
#3510596
by goz, just_like_good_vibes: [2.0.4] Improve prop value rendering for booleans
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Issue
#3510596
by goz, just_like_good_vibes: [2.0.4] Improve prop value rendering for booleans
issue/ui_patterns-3510596:3510596-improved
into
2.0.x
Overview
0
Commits
3
Pipelines
3
Changes
7
Merged
Mikael Meulle
requested to merge
issue/ui_patterns-3510596:3510596-improved
into
2.0.x
2 weeks ago
Overview
0
Commits
3
Pipelines
3
Changes
7
Expand
Closes
#3510596
0
0
Merge request reports
Compare
2.0.x
version 2
4dd9b27b
2 weeks ago
version 1
e8974f02
2 weeks ago
2.0.x (base)
and
latest version
latest version
f853f136
3 commits,
2 weeks ago
version 2
4dd9b27b
3 commits,
2 weeks ago
version 1
e8974f02
1 commit,
2 weeks ago
7 files
+
141
−
24
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
7
Search (e.g. *.vue) (Ctrl+P)
src/Element/ComponentElementBuilder.php
+
28
−
8
Options
@@ -98,19 +98,39 @@ class ComponentElementBuilder implements TrustedCallbackInterface {
}
}
else
{
if
(
!
empty
(
$data
)
||
$prop_type
->
getPluginId
()
===
'attributes'
)
{
// For JSON Schema validator, empty value is not the same as missing
// value, and we want to prevent some of the prop types rules to be
// applied on empty values: string pattern, string format,
// enum, number min/max...
// However, we don't remove empty attributes to avoid an error with
// Drupal\Core\Template\TwigExtension::createAttribute() when themers
// forget to use the default({}) filter.
if
(
!
static
::
isPropValueEmpty
(
$data
,
$prop_type
))
{
$build
[
'#props'
][
$prop_or_slot_id
]
=
$data
;
}
}
}
/**
* Determine if a prop value is empty.
*
* @param mixed $data
* The prop value.
* @param \Drupal\ui_patterns\PropTypeInterface $prop_type
* Target prop type.
*
* @return bool
* TRUE if the prop value is empty, FALSE otherwise.
*/
protected
static
function
isPropValueEmpty
(
mixed
$data
,
PropTypeInterface
$prop_type
):
bool
{
// For JSON Schema validator, empty value is not the same as missing
// value, and we want to prevent some of the prop types rules to be
// applied on empty values: string pattern, string format,
// enum, number min/max...
// However, we don't remove empty attributes to avoid an error with
// Drupal\Core\Template\TwigExtension::createAttribute() when themers
// forget to use the default({}) filter.
// For boolean values, we only remove NULL values.
return
match
(
$prop_type
->
getPluginId
())
{
'attributes'
=>
FALSE
,
'boolean'
=>
(
$data
===
NULL
),
default
=>
empty
(
$data
),
};
}
/**
* Update the build array for a configured source on a prop/slot.
*
Loading