From 5dbebc7be36ed65668e4c2cd8d13bc262675e95b Mon Sep 17 00:00:00 2001 From: webchick Date: Tue, 10 Dec 2013 22:54:07 -0800 Subject: [PATCH] Issue #2061971 by naveenvalecha, herom, InternetDevels: Replace user_access() calls with ->hasPermission() in block module. --- .../custom_block/CustomBlockFormController.php | 5 +++-- .../Plugin/Block/CustomBlockBlock.php | 18 +++++++++++++++--- .../lib/Drupal/block/BlockAccessController.php | 2 +- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockFormController.php b/core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockFormController.php index ebe7ade8689..cbabf5a49ea 100644 --- a/core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockFormController.php +++ b/core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockFormController.php @@ -40,6 +40,7 @@ class CustomBlockFormController extends ContentEntityFormController { */ public function form(array $form, array &$form_state) { $block = $this->entity; + $account = $this->currentUser(); if ($this->operation == 'edit') { $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'), ), '#weight' => 20, - '#access' => $block->isNewRevision() || user_access('administer blocks'), + '#access' => $block->isNewRevision() || $account->hasPermission('administer blocks'), ); $form['revision_information']['revision'] = array( '#type' => 'checkbox', '#title' => t('Create new revision'), '#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. diff --git a/core/modules/block/custom_block/lib/Drupal/custom_block/Plugin/Block/CustomBlockBlock.php b/core/modules/block/custom_block/lib/Drupal/custom_block/Plugin/Block/CustomBlockBlock.php index a2a995989da..bfd6ebb5c74 100644 --- a/core/modules/block/custom_block/lib/Drupal/custom_block/Plugin/Block/CustomBlockBlock.php +++ b/core/modules/block/custom_block/lib/Drupal/custom_block/Plugin/Block/CustomBlockBlock.php @@ -12,6 +12,7 @@ use Drupal\block\Annotation\Block; use Drupal\Core\Annotation\Translation; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\Core\Extension\ModuleHandlerInterface; +use Drupal\Core\Session\AccountInterface; use Drupal\block\Plugin\Type\BlockManager; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -41,6 +42,13 @@ class CustomBlockBlock extends BlockBase implements ContainerFactoryPluginInterf */ protected $moduleHandler; + /** + * The Drupal account to use for checking for access to block. + * + * @var \Drupal\Core\Session\AccountInterface. + */ + protected $account; + /** * Constructs a new CustomBlockBlock. * @@ -54,12 +62,15 @@ class CustomBlockBlock extends BlockBase implements ContainerFactoryPluginInterf * The Plugin Block Manager. * @param \Drupal\Core\Extension\ModuleHandlerInterface * 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); $this->blockManager = $block_manager; $this->moduleHandler = $module_handler; + $this->account = $account; } /** @@ -71,7 +82,8 @@ class CustomBlockBlock extends BlockBase implements ContainerFactoryPluginInterf $plugin_id, $plugin_definition, $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, '!url' => url('block/add') )), - '#access' => user_access('administer blocks') + '#access' => $this->account->hasPermission('administer blocks') ); } } diff --git a/core/modules/block/lib/Drupal/block/BlockAccessController.php b/core/modules/block/lib/Drupal/block/BlockAccessController.php index 2355c00ad23..a82de8b144a 100644 --- a/core/modules/block/lib/Drupal/block/BlockAccessController.php +++ b/core/modules/block/lib/Drupal/block/BlockAccessController.php @@ -58,7 +58,7 @@ class BlockAccessController extends EntityAccessController implements EntityCont */ protected function checkAccess(EntityInterface $entity, $operation, $langcode, AccountInterface $account) { if ($operation != 'view') { - return user_access('administer blocks', $account); + return $account->hasPermission('administer blocks'); } // Deny access to disabled blocks.