Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
U
ui_patterns_settings
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_settings
Commits
207d6352
Commit
207d6352
authored
1 year ago
by
Pierre Dureau
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3345071
by pdureau: Fix links setting type
parent
cbb24f3a
Branches
Branches containing commit
Tags
Tags containing commit
2 merge requests
!32
Add inital media modul
,
!18
Issue #3345071 by pdureau: Fix links setting type
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/Plugin/ComplexSettingTypeBase.php
+1
-1
1 addition, 1 deletion
src/Plugin/ComplexSettingTypeBase.php
src/Plugin/UiPatterns/SettingType/LinksSettingType.php
+21
-62
21 additions, 62 deletions
src/Plugin/UiPatterns/SettingType/LinksSettingType.php
with
22 additions
and
63 deletions
src/Plugin/ComplexSettingTypeBase.php
+
1
−
1
View file @
207d6352
...
...
@@ -95,7 +95,7 @@ abstract class ComplexSettingTypeBase extends PatternSettingTypeBase implements
$this
->
provider
=
$instance
;
return
$instance
->
getData
(
$value
[
'configuration'
][
$provider_id
][
'config'
]
??
[]);
}
return
[]
;
return
$value
;
}
/**
...
...
This diff is collapsed.
Click to expand it.
src/Plugin/UiPatterns/SettingType/LinksSettingType.php
+
21
−
62
View file @
207d6352
...
...
@@ -2,6 +2,8 @@
namespace
Drupal\ui_patterns_settings\Plugin\UiPatterns\SettingType
;
use
Drupal\Core\Template\Attribute
;
use
Drupal\Core\Url
;
use
Drupal\ui_patterns_settings
\Plugin\ComplexSettingTypeBase
;
/**
...
...
@@ -51,15 +53,7 @@ class LinksSettingType extends ComplexSettingTypeBase {
$item
[
"url"
]
->
setOptions
(
$item
[
"link"
][
"#options"
]);
unset
(
$item
[
"link"
]);
}
if
(
array_key_exists
(
"url"
,
$item
)
&&
(
$item
[
"url"
]
instanceof
Url
))
{
// Examples: menu.html.twig, links.html.twig.
$url
=
$item
[
"url"
];
$item
[
"url"
]
=
$url
->
toString
();
$options
=
$url
->
getOptions
();
if
(
isset
(
$options
[
"attributes"
]))
{
$item
[
"link_attributes"
]
=
new
Attribute
(
$options
[
"attributes"
]);
}
}
$item
=
self
::
normalizeUrl
(
$item
);
if
(
array_key_exists
(
"below"
,
$item
))
{
$item
[
"below"
]
=
self
::
normalize
(
$item
[
"below"
]);
}
...
...
@@ -69,67 +63,32 @@ class LinksSettingType extends ComplexSettingTypeBase {
}
/**
* Convert pager to menu.
*
* Convert pager data structure to menu data structure. Useful for
* pager.html.twig presenter template.
* Normaize URL in an item.
*
* @param array $items
* The pager items to convert.
* @param int $current
* The current page.
*
* @return array
* Useful for: menu.html.twig, links.html.twig.
*/
public
static
function
convertPagerToMenu
(
array
$pager
,
int
$current
):
array
{
$items
=
[];
if
(
isset
(
$pager
[
"first"
]))
{
$items
[]
=
$pager
[
"first"
];
private
static
function
normalizeUrl
(
array
$item
):
array
{
if
(
!
array_key_exists
(
"url"
,
$item
))
{
return
$item
;
}
if
(
isset
(
$pager
[
"previous"
]))
{
$items
[]
=
$pager
[
"previous"
];
$url
=
$item
[
"url"
];
if
(
!
(
$url
instanceof
Url
))
{
return
$item
;
}
if
(
isset
(
$pager
[
"pages"
]))
{
foreach
(
$pager
[
"pages"
]
as
$index
=>
$item
)
{
$item
[
"text"
]
=
$index
;
if
(
$index
==
$current
)
{
unset
(
$item
[
"href"
]);
}
$items
[]
=
$item
;
}
}
if
(
isset
(
$pager
[
"next"
]))
{
$items
[]
=
$pager
[
"next"
];
if
(
$url
->
isRouted
()
&&
(
$url
->
getRouteName
()
===
'<nolink>'
))
{
unset
(
$item
[
"url"
]);
}
if
(
isset
(
$pager
[
"last"
]
))
{
$items
[]
=
$pager
[
"last
"
];
elseif
(
$url
->
isRouted
()
&&
(
$url
->
getRouteName
()
===
'<button>'
))
{
unset
(
$item
[
"url
"
]
)
;
}
return
$items
;
}
/**
* Convert mini pager to menu.
*
* Convert views mini pager data structure to menu data structure. Useful for
* views-mini-pager.html.twig presenter template.
*
* @param array $items
* The pager items to convert.
*
* @return array
*/
public
static
function
convertMiniPagerToMenu
(
array
$pager
):
array
{
$items
=
[];
if
(
$pager
[
"previous"
])
{
$items
[]
=
$pager
[
"previous"
];
else
{
$item
[
"url"
]
=
$url
->
toString
();
}
$items
[]
=
[
"text"
=>
$pager
[
"current"
],
];
if
(
$pager
[
"next"
])
{
$items
[]
=
$pager
[
"next"
];
$options
=
$url
->
getOptions
();
if
(
isset
(
$options
[
"attributes"
]))
{
$item
[
"link_attributes"
]
=
new
Attribute
(
$options
[
"attributes"
]);
}
return
$item
s
;
return
$item
;
}
}
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