Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
U
uw_cfg_common
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
WCMS
uw_cfg_common
Commits
a2945110
Commit
a2945110
authored
3 years ago
by
Liam Morland
Browse files
Options
Downloads
Patches
Plain Diff
ISTWCMS-4635: Create UWDropbutton with access check
parent
ece2c7ee
No related branches found
No related tags found
1 merge request
!105
ISTWCMS-4635: Create UWDropbutton with access check
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/Plugin/views/field/UWDropbutton.php
+42
-0
42 additions, 0 deletions
src/Plugin/views/field/UWDropbutton.php
uw_cfg_common.module
+8
-0
8 additions, 0 deletions
uw_cfg_common.module
with
50 additions
and
0 deletions
src/Plugin/views/field/UWDropbutton.php
0 → 100644
+
42
−
0
View file @
a2945110
<?php
namespace
Drupal\uw_cfg_common\Plugin\views\field
;
use
Drupal\views\Plugin\views\field\Dropbutton
;
use
Drupal\views\ResultRow
;
/**
* Provides a handler that renders links as dropbutton with access check.
*
* Identical to parent class except that render() removes links for which the
* user has no access.
*
* @ingroup views_field_handlers
*
* @ViewsField("uwdropbutton")
*/
class
UWDropbutton
extends
Dropbutton
{
/**
* {@inheritdoc}
*/
public
function
render
(
ResultRow
$values
)
{
$links
=
[];
foreach
(
$this
->
getLinks
()
as
$link
)
{
if
(
$link
[
'url'
]
->
access
())
{
$links
[]
=
$link
;
}
}
if
(
!
empty
(
$links
))
{
return
[
'#type'
=>
'dropbutton'
,
'#links'
=>
$links
,
];
}
else
{
return
''
;
}
}
}
This diff is collapsed.
Click to expand it.
uw_cfg_common.module
+
8
−
0
View file @
a2945110
...
@@ -581,3 +581,11 @@ function uw_cfg_common_block_content_create_access(AccountInterface $account, ar
...
@@ -581,3 +581,11 @@ function uw_cfg_common_block_content_create_access(AccountInterface $account, ar
// No opinion.
// No opinion.
return
AccessResult
::
neutral
();
return
AccessResult
::
neutral
();
}
}
/**
* Implements hook_views_plugins_field_alter().
*/
function
uw_cfg_common_views_plugins_field_alter
(
array
&
$plugins
):
void
{
// Replace Drupal\views\Plugin\views\field\Dropbutton with UW version.
$plugins
[
'dropbutton'
][
'class'
]
=
'Drupal\uw_cfg_common\Plugin\views\field\UWDropbutton'
;
}
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