Commit 5dbebc7b authored by webchick's avatar webchick

Issue #2061971 by naveenvalecha, herom, InternetDevels: Replace user_access()...

Issue #2061971 by naveenvalecha, herom, InternetDevels: Replace user_access() calls with ->hasPermission() in block module.
parent 4e6b6ba3
......@@ -40,6 +40,7 @@ protected function prepareEntity() {
*/
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 @@ public function form(array $form, array &$form_state) {
'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.
......
......@@ -12,6 +12,7 @@
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 @@ public static function create(ContainerInterface $container, array $configuratio
$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 @@ public function build() {
'%uuid' => $uuid,
'!url' => url('block/add')
)),
'#access' => user_access('administer blocks')
'#access' => $this->account->hasPermission('administer blocks')
);
}
}
......
......@@ -58,7 +58,7 @@ public static function createInstance(ContainerInterface $container, $entity_typ
*/
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.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment