Skip to content
Snippets Groups Projects
Commit 26e4120b authored by Viktor Holovachek's avatar Viktor Holovachek Committed by Eirik Morland
Browse files

Issue #3402338 by astonvictor, eiriksm, schillerm: Add permission to view the block

parent 82a843c9
No related branches found
No related tags found
1 merge request!93402338 - Add view permission
Pipeline #312135 failed
<?php
/**
* @file
* Install, update, and uninstall functions for Git Info.
*/
use Drupal\user\Entity\Role;
/**
* Set user permissions.
*/
function git_info_update_8001() {
foreach (['anonymous', 'authenticated'] as $item) {
if ($role = Role::load($item)) {
$role->grantPermission('view git info');
$role->save();
}
}
}
view git info:
title: 'View git info'
description: 'Allows to view information about git.'
......@@ -2,8 +2,10 @@
namespace Drupal\git_info\Plugin\Block;
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Block\BlockBase;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\git_info\GitInfo;
use Drupal\git_info\GitInfoInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
......@@ -65,6 +67,13 @@ class InfoBlock extends BlockBase implements ContainerFactoryPluginInterface {
return $build;
}
/**
* {@inheritdoc}
*/
protected function blockAccess(AccountInterface $account) {
return AccessResult::allowedIfHasPermission($account, 'view git info');
}
/**
* {@inheritdoc}
*/
......
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