Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ActionPool.php
Go to the documentation of this file.
1 <?php
7 
13 
18 {
22  const ACTIONS_PAGE_TOOLBAR = 'page.actions.toolbar';
23 
29  protected $context;
30 
36  protected $items;
37 
43  protected $itemFactory;
44 
48  protected $toolbarBlock;
49 
56  public function __construct(Context $context, ItemFactory $itemFactory)
57  {
58  $this->context = $context;
59  $this->itemFactory = $itemFactory;
60  }
61 
67  public function getToolbar()
68  {
69  return $this->context->getPageLayout()
70  ? $this->context->getPageLayout()->getBlock(static::ACTIONS_PAGE_TOOLBAR)
71  : false;
72  }
73 
82  public function add($key, array $data, UiComponentInterface $component)
83  {
84  $data['id'] = isset($data['id']) ? $data['id'] : $key;
85 
86  $toolbar = $this->getToolbar();
87  if ($toolbar !== false) {
88  $this->items[$key] = $this->itemFactory->create();
89  $this->items[$key]->setData($data);
90  $container = $this->createContainer($key, $component);
91  $toolbar->setChild($key, $container);
92  }
93  }
94 
101  public function remove($key)
102  {
103  unset($this->items[$key]);
104  }
105 
113  public function update($key, array $data)
114  {
115  if (isset($this->items[$key])) {
116  $this->items[$key]->setData($data);
117  }
118  }
119 
128  public function addHtmlBlock($type, $name = '', array $arguments = [])
129  {
130  $toolbar = $this->getToolbar();
131  $container = $this->context->getPageLayout()->createBlock($type, $name, $arguments);
132  if ($toolbar) {
133  $toolbar->setChild($name, $container);
134  }
135  }
136 
144  protected function createContainer($key, UiComponentInterface $view)
145  {
146  $container = $this->context->getPageLayout()->createBlock(
147  \Magento\Ui\Component\Control\Container::class,
148  'container-' . $view->getName() . '-' . $key,
149  [
150  'data' => [
151  'button_item' => $this->items[$key],
152  'context' => $view,
153  ]
154  ]
155  );
156 
157  return $container;
158  }
159 }
add($key, array $data, UiComponentInterface $component)
Definition: ActionPool.php:82
$type
Definition: item.phtml:13
$arguments
addHtmlBlock($type, $name='', array $arguments=[])
Definition: ActionPool.php:128
__construct(Context $context, ItemFactory $itemFactory)
Definition: ActionPool.php:56
createContainer($key, UiComponentInterface $view)
Definition: ActionPool.php:144
if(!isset($_GET['name'])) $name
Definition: log.php:14