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
Merge requests
!18
Issue
#3345071
by pdureau: Fix links setting type
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Issue
#3345071
by pdureau: Fix links setting type
issue/ui_patterns_settings-3345071:3345071-fixes-for-2.1
into
8.x-2.x
Overview
0
Commits
1
Pipelines
0
Changes
2
Merged
Pierre Dureau
requested to merge
issue/ui_patterns_settings-3345071:3345071-fixes-for-2.1
into
8.x-2.x
1 year ago
Overview
0
Commits
1
Pipelines
0
Changes
2
Expand
Closes
#3345071
0
0
Merge request reports
Compare
8.x-2.x
8.x-2.x (base)
and
latest version
latest version
207d6352
1 commit,
1 year ago
2 files
+
22
−
63
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
2
Search (e.g. *.vue) (Ctrl+P)
src/Plugin/UiPatterns/SettingType/LinksSettingType.php
+
21
−
62
Options
@@ -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
;
}
}
Loading