Skip to content
Snippets Groups Projects
Commit abb04fa5 authored by Lily Yan's avatar Lily Yan
Browse files

Merge branch 'feature/ISTWCMS-4635-UWDropbutton' into '1.0.x'

ISTWCMS-4635: Create UWDropbutton with access check

See merge request !105
parents ece2c7ee a2945110
No related branches found
No related tags found
1 merge request!105ISTWCMS-4635: Create UWDropbutton with access check
<?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 '';
}
}
}
......@@ -581,3 +581,11 @@ function uw_cfg_common_block_content_create_access(AccountInterface $account, ar
// No opinion.
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';
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment