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
71517119
Commit
71517119
authored
6 months ago
by
Sviatoslav Smovdyr
Committed by
Mikael Meulle
6 months ago
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3483496
by smovs, just_like_good_vibes, pdureau: Preselect option when only one available
parent
e6a1e80d
No related branches found
No related tags found
1 merge request
!260
#3483496 - Made autoselect for a single option in the select. Simplified the...
Pipeline
#348659
passed
6 months ago
Stage: build
Stage: validate
Stage: test
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/Plugin/UiPatterns/Source/DerivableContextSourceBase.php
+4
-0
4 additions, 0 deletions
src/Plugin/UiPatterns/Source/DerivableContextSourceBase.php
src/Plugin/UiPatterns/Source/EntityReferencedSource.php
+35
-1
35 additions, 1 deletion
src/Plugin/UiPatterns/Source/EntityReferencedSource.php
with
39 additions
and
1 deletion
src/Plugin/UiPatterns/Source/DerivableContextSourceBase.php
+
4
−
0
View file @
71517119
...
@@ -278,6 +278,10 @@ abstract class DerivableContextSourceBase extends SourcePluginBase {
...
@@ -278,6 +278,10 @@ abstract class DerivableContextSourceBase extends SourcePluginBase {
}
}
}
}
}
}
// Set default value to the only available option.
if
(
!
$derivable_context
&&
count
(
$options_derivable_contexts
)
===
1
)
{
$derivable_context
=
array_key_first
(
$options_derivable_contexts
);
}
return
$derivable_context
;
return
$derivable_context
;
}
}
...
...
This diff is collapsed.
Click to expand it.
src/Plugin/UiPatterns/Source/EntityReferencedSource.php
+
35
−
1
View file @
71517119
...
@@ -46,7 +46,7 @@ class EntityReferencedSource extends DerivableContextSourceBase {
...
@@ -46,7 +46,7 @@ class EntityReferencedSource extends DerivableContextSourceBase {
$returned
=
[];
$returned
=
[];
foreach
(
$options
as
$option_key
=>
$option_value
)
{
foreach
(
$options
as
$option_key
=>
$option_value
)
{
if
(
!
isset
(
$option_to_group
[
$option_key
]))
{
if
(
!
isset
(
$option_to_group
[
$option_key
]))
{
$returned
[
$option_key
]
=
$option_value
;
$returned
[
$option_key
]
=
(
string
)
$this
->
getSimplifiedOptionWording
(
$option_value
)
;
}
}
}
}
foreach
(
$groups
as
$group_key
=>
$grouped_option_keys
)
{
foreach
(
$groups
as
$group_key
=>
$grouped_option_keys
)
{
...
@@ -55,6 +55,7 @@ class EntityReferencedSource extends DerivableContextSourceBase {
...
@@ -55,6 +55,7 @@ class EntityReferencedSource extends DerivableContextSourceBase {
foreach
(
$grouped_option_keys
as
$grouped_option_key
)
{
foreach
(
$grouped_option_keys
as
$grouped_option_key
)
{
if
(
$grouped_option_key
!==
$group_key
)
{
if
(
$grouped_option_key
!==
$group_key
)
{
$label
=
(
string
)
$options
[
$grouped_option_key
];
$label
=
(
string
)
$options
[
$grouped_option_key
];
// @phpstan-ignore-next-line
$returned
[
$group
][
$grouped_option_key
]
=
explode
(
" referenced by "
,
$label
)[
0
];
$returned
[
$group
][
$grouped_option_key
]
=
explode
(
" referenced by "
,
$label
)[
0
];
}
}
}
}
...
@@ -111,4 +112,37 @@ class EntityReferencedSource extends DerivableContextSourceBase {
...
@@ -111,4 +112,37 @@ class EntityReferencedSource extends DerivableContextSourceBase {
];
];
}
}
/**
* Return simplified wording for an option.
*
* @param mixed $option_value
* The option value.
*
* @return mixed
* The simplified option.
*/
protected
function
getSimplifiedOptionWording
(
mixed
$option_value
):
mixed
{
if
(
!
(
$option_value
instanceof
TranslatableMarkup
))
{
return
$option_value
;
}
$arguments
=
$option_value
->
getArguments
();
// Modify @bundle to keep only the part before any parentheses.
if
(
isset
(
$arguments
[
'@bundle'
]))
{
$bundle_value
=
$arguments
[
'@bundle'
];
// Keep only the part before parentheses, if present.
if
(
is_string
(
$bundle_value
)
&&
preg_match
(
'/^(.*?)\s*\(/'
,
$bundle_value
,
$matches
))
{
$arguments
[
'@bundle'
]
=
trim
(
$matches
[
1
]);
}
}
return
new
TranslatableMarkup
(
'@field (@bundle)'
,
$arguments
,
$option_value
->
getOptions
()
);
}
}
}
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