Issue #2061971 by naveenvalecha, herom, InternetDevels: Replace user_access() calls with ->hasPermission() in block module.
parent
4e6b6ba3b8
commit
5dbebc7be3
|
@ -40,6 +40,7 @@ class CustomBlockFormController extends ContentEntityFormController {
|
||||||
*/
|
*/
|
||||||
public function form(array $form, array &$form_state) {
|
public function form(array $form, array &$form_state) {
|
||||||
$block = $this->entity;
|
$block = $this->entity;
|
||||||
|
$account = $this->currentUser();
|
||||||
|
|
||||||
if ($this->operation == 'edit') {
|
if ($this->operation == 'edit') {
|
||||||
$form['#title'] = $this->t('Edit custom block %label', array('%label' => $block->label()));
|
$form['#title'] = $this->t('Edit custom block %label', array('%label' => $block->label()));
|
||||||
|
@ -96,14 +97,14 @@ class CustomBlockFormController extends ContentEntityFormController {
|
||||||
'js' => array(drupal_get_path('module', 'custom_block') . '/custom_block.js'),
|
'js' => array(drupal_get_path('module', 'custom_block') . '/custom_block.js'),
|
||||||
),
|
),
|
||||||
'#weight' => 20,
|
'#weight' => 20,
|
||||||
'#access' => $block->isNewRevision() || user_access('administer blocks'),
|
'#access' => $block->isNewRevision() || $account->hasPermission('administer blocks'),
|
||||||
);
|
);
|
||||||
|
|
||||||
$form['revision_information']['revision'] = array(
|
$form['revision_information']['revision'] = array(
|
||||||
'#type' => 'checkbox',
|
'#type' => 'checkbox',
|
||||||
'#title' => t('Create new revision'),
|
'#title' => t('Create new revision'),
|
||||||
'#default_value' => $block->isNewRevision(),
|
'#default_value' => $block->isNewRevision(),
|
||||||
'#access' => user_access('administer blocks'),
|
'#access' => $account->hasPermission('administer blocks'),
|
||||||
);
|
);
|
||||||
|
|
||||||
// Check the revision log checkbox when the log textarea is filled in.
|
// Check the revision log checkbox when the log textarea is filled in.
|
||||||
|
|
|
@ -12,6 +12,7 @@ use Drupal\block\Annotation\Block;
|
||||||
use Drupal\Core\Annotation\Translation;
|
use Drupal\Core\Annotation\Translation;
|
||||||
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
|
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
|
||||||
use Drupal\Core\Extension\ModuleHandlerInterface;
|
use Drupal\Core\Extension\ModuleHandlerInterface;
|
||||||
|
use Drupal\Core\Session\AccountInterface;
|
||||||
use Drupal\block\Plugin\Type\BlockManager;
|
use Drupal\block\Plugin\Type\BlockManager;
|
||||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||||
|
|
||||||
|
@ -41,6 +42,13 @@ class CustomBlockBlock extends BlockBase implements ContainerFactoryPluginInterf
|
||||||
*/
|
*/
|
||||||
protected $moduleHandler;
|
protected $moduleHandler;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Drupal account to use for checking for access to block.
|
||||||
|
*
|
||||||
|
* @var \Drupal\Core\Session\AccountInterface.
|
||||||
|
*/
|
||||||
|
protected $account;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a new CustomBlockBlock.
|
* Constructs a new CustomBlockBlock.
|
||||||
*
|
*
|
||||||
|
@ -54,12 +62,15 @@ class CustomBlockBlock extends BlockBase implements ContainerFactoryPluginInterf
|
||||||
* The Plugin Block Manager.
|
* The Plugin Block Manager.
|
||||||
* @param \Drupal\Core\Extension\ModuleHandlerInterface
|
* @param \Drupal\Core\Extension\ModuleHandlerInterface
|
||||||
* The Module Handler.
|
* The Module Handler.
|
||||||
|
* @param \Drupal\Core\Session\AccountInterface $account
|
||||||
|
* The account for which view access should be checked.
|
||||||
*/
|
*/
|
||||||
public function __construct(array $configuration, $plugin_id, array $plugin_definition, BlockManager $block_manager, ModuleHandlerInterface $module_handler) {
|
public function __construct(array $configuration, $plugin_id, array $plugin_definition, BlockManager $block_manager, ModuleHandlerInterface $module_handler, AccountInterface $account) {
|
||||||
parent::__construct($configuration, $plugin_id, $plugin_definition);
|
parent::__construct($configuration, $plugin_id, $plugin_definition);
|
||||||
|
|
||||||
$this->blockManager = $block_manager;
|
$this->blockManager = $block_manager;
|
||||||
$this->moduleHandler = $module_handler;
|
$this->moduleHandler = $module_handler;
|
||||||
|
$this->account = $account;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -71,7 +82,8 @@ class CustomBlockBlock extends BlockBase implements ContainerFactoryPluginInterf
|
||||||
$plugin_id,
|
$plugin_id,
|
||||||
$plugin_definition,
|
$plugin_definition,
|
||||||
$container->get('plugin.manager.block'),
|
$container->get('plugin.manager.block'),
|
||||||
$container->get('module_handler')
|
$container->get('module_handler'),
|
||||||
|
$container->get('current_user')
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -134,7 +146,7 @@ class CustomBlockBlock extends BlockBase implements ContainerFactoryPluginInterf
|
||||||
'%uuid' => $uuid,
|
'%uuid' => $uuid,
|
||||||
'!url' => url('block/add')
|
'!url' => url('block/add')
|
||||||
)),
|
)),
|
||||||
'#access' => user_access('administer blocks')
|
'#access' => $this->account->hasPermission('administer blocks')
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,7 +58,7 @@ class BlockAccessController extends EntityAccessController implements EntityCont
|
||||||
*/
|
*/
|
||||||
protected function checkAccess(EntityInterface $entity, $operation, $langcode, AccountInterface $account) {
|
protected function checkAccess(EntityInterface $entity, $operation, $langcode, AccountInterface $account) {
|
||||||
if ($operation != 'view') {
|
if ($operation != 'view') {
|
||||||
return user_access('administer blocks', $account);
|
return $account->hasPermission('administer blocks');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deny access to disabled blocks.
|
// Deny access to disabled blocks.
|
||||||
|
|
Loading…
Reference in New Issue