Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
U
uw_dashboard
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
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_dashboard
Commits
0dee0f17
Commit
0dee0f17
authored
11 months ago
by
Eric Bremner
Browse files
Options
Downloads
Patches
Plain Diff
ISTWCMS-5412: adding block visibility and permissions to publication references block
parent
ee7d0689
No related branches found
No related tags found
1 merge request
!35
Feature/istwcms 5412 ebremner bicite dashboard blocks
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/Plugin/Block/PublicationReferenceBlock.php
+31
-2
31 additions, 2 deletions
src/Plugin/Block/PublicationReferenceBlock.php
with
31 additions
and
2 deletions
src/Plugin/Block/PublicationReferenceBlock.php
+
31
−
2
View file @
0dee0f17
...
@@ -2,10 +2,13 @@
...
@@ -2,10 +2,13 @@
namespace
Drupal\uw_dashboard\Plugin\Block
;
namespace
Drupal\uw_dashboard\Plugin\Block
;
use
Drupal\Core\Access\AccessResult
;
use
Drupal\Core\Block\BlockBase
;
use
Drupal\Core\Block\BlockBase
;
use
Drupal\Core\Entity\EntityTypeManagerInterface
;
use
Drupal\Core\Entity\EntityTypeManagerInterface
;
use
Drupal\Core\Form\FormStateInterface
;
use
Drupal\Core\Form\FormStateInterface
;
use
Drupal\Core\Plugin\ContainerFactoryPluginInterface
;
use
Drupal\Core\Plugin\ContainerFactoryPluginInterface
;
use
Drupal\Core\Session\AccountInterface
;
use
Drupal\Core\Session\AccountProxyInterface
;
use
Symfony\Component\DependencyInjection\ContainerInterface
;
use
Symfony\Component\DependencyInjection\ContainerInterface
;
/**
/**
...
@@ -25,6 +28,13 @@ class PublicationReferenceBlock extends BlockBase implements ContainerFactoryPlu
...
@@ -25,6 +28,13 @@ class PublicationReferenceBlock extends BlockBase implements ContainerFactoryPlu
*/
*/
protected
$entityTypeManager
;
protected
$entityTypeManager
;
/**
* The current user.
*
* @var \Drupal\Core\Session\AccountProxyInterface
*/
protected
$currentUser
;
/**
/**
* {@inheritdoc}
* {@inheritdoc}
*/
*/
...
@@ -38,7 +48,8 @@ class PublicationReferenceBlock extends BlockBase implements ContainerFactoryPlu
...
@@ -38,7 +48,8 @@ class PublicationReferenceBlock extends BlockBase implements ContainerFactoryPlu
$configuration
,
$configuration
,
$plugin_id
,
$plugin_id
,
$plugin_definition
,
$plugin_definition
,
$container
->
get
(
'entity_type.manager'
)
$container
->
get
(
'entity_type.manager'
),
$container
->
get
(
'current_user'
)
);
);
}
}
...
@@ -53,15 +64,19 @@ class PublicationReferenceBlock extends BlockBase implements ContainerFactoryPlu
...
@@ -53,15 +64,19 @@ class PublicationReferenceBlock extends BlockBase implements ContainerFactoryPlu
* The plugin implementation definition.
* The plugin implementation definition.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager
* Entity type manager.
* Entity type manager.
* @param \Drupal\Core\Session\AccountProxyInterface $currentUser
* The current user.
*/
*/
public
function
__construct
(
public
function
__construct
(
array
$configuration
,
array
$configuration
,
$plugin_id
,
$plugin_id
,
$plugin_definition
,
$plugin_definition
,
EntityTypeManagerInterface
$entityTypeManager
EntityTypeManagerInterface
$entityTypeManager
,
AccountProxyInterface
$currentUser
)
{
)
{
parent
::
__construct
(
$configuration
,
$plugin_id
,
$plugin_definition
);
parent
::
__construct
(
$configuration
,
$plugin_id
,
$plugin_definition
);
$this
->
entityTypeManager
=
$entityTypeManager
;
$this
->
entityTypeManager
=
$entityTypeManager
;
$this
->
currentUser
=
$currentUser
;
}
}
/**
/**
...
@@ -69,6 +84,13 @@ class PublicationReferenceBlock extends BlockBase implements ContainerFactoryPlu
...
@@ -69,6 +84,13 @@ class PublicationReferenceBlock extends BlockBase implements ContainerFactoryPlu
*/
*/
public
function
build
()
{
public
function
build
()
{
// Add a message if the user does not have access to the block.
if
(
!
$this
->
currentUser
->
hasPermission
(
'edit any bibcite_reference'
))
{
return
[
'#markup'
=>
'You do not have permission to view this block.'
,
];
}
// Load the view.
// Load the view.
/** @var \Drupal\views\ViewExecutable $view */
/** @var \Drupal\views\ViewExecutable $view */
$view
=
$this
->
entityTypeManager
$view
=
$this
->
entityTypeManager
...
@@ -120,4 +142,11 @@ class PublicationReferenceBlock extends BlockBase implements ContainerFactoryPlu
...
@@ -120,4 +142,11 @@ class PublicationReferenceBlock extends BlockBase implements ContainerFactoryPlu
}
}
/**
* {@inheritdoc}
*/
protected
function
blockAccess
(
AccountInterface
$account
)
{
return
AccessResult
::
allowedIfHasPermission
(
$account
,
'edit any bibcite_reference'
);
}
}
}
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