Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Massaction.php
Go to the documentation of this file.
1 <?php
8 
14 
22 class Massaction extends \Magento\Backend\Block\Widget\Grid\Massaction\AbstractMassaction
23 {
27  private $authorization;
28 
35  private $restrictions = [
36  'enable' => 'Magento_Backend::toggling_cache_type',
37  'disable' => 'Magento_Backend::toggling_cache_type',
38  'refresh' => 'Magento_Backend::refresh_cache_type',
39  ];
40 
49  public function __construct(
50  Context $context,
51  EncoderInterface $jsonEncoder,
52  array $data = [],
53  AuthorizationInterface $authorization = null
54  ) {
55  $this->authorization = $authorization ?: ObjectManager::getInstance()->get(AuthorizationInterface::class);
56 
57  parent::__construct($context, $jsonEncoder, $data);
58  }
59 
69  public function addItem($itemId, $item)
70  {
71  if (!$this->isRestricted($itemId)) {
72  parent::addItem($itemId, $item);
73  }
74 
75  return $this;
76  }
77 
85  private function isRestricted(string $itemId): bool
86  {
87  if (!key_exists($itemId, $this->restrictions)) {
88  return false;
89  }
90 
91  return !$this->authorization->isAllowed($this->restrictions[$itemId]);
92  }
93 }
__construct(Context $context, EncoderInterface $jsonEncoder, array $data=[], AuthorizationInterface $authorization=null)
Definition: Massaction.php:49