Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ShortcutButtons.php
Go to the documentation of this file.
1 <?php
6 namespace Magento\Catalog\Block;
7 
9 
19 {
23  const POSITION_BEFORE = 'before';
24 
25  const POSITION_AFTER = 'after';
26 
30  protected $_shortcuts = [];
31 
35  protected $_isCatalogProduct;
36 
40  protected $_orPosition;
41 
48  public function __construct(
49  Template\Context $context,
50  $isCatalogProduct = false,
51  $orPosition = null,
52  array $data = []
53  ) {
54  parent::__construct($context, $data);
55  $this->_isCatalogProduct = $isCatalogProduct;
56  $this->_orPosition = $orPosition ?: ($isCatalogProduct ? self::POSITION_BEFORE : self::POSITION_AFTER);
57  }
58 
65  public function addShortcut(Template $block)
66  {
67  if ($block instanceof ShortcutInterface) {
68  $this->_shortcuts[] = $block;
69  }
70  }
71 
76  protected function _beforeToHtml()
77  {
78  $this->_eventManager->dispatch(
79  'shortcut_buttons_container',
80  [
81  'container' => $this,
82  'is_catalog_product' => $this->_isCatalogProduct,
83  'or_position' => $this->_orPosition
84  ]
85  );
86  return $this;
87  }
88 
94  protected function _toHtml()
95  {
97  foreach ($this->_shortcuts as $shortcut) {
98  $this->setChild($shortcut->getAlias(), $shortcut);
99  }
100  return $this->getChildHtml();
101  }
102 }
__construct(Template\Context $context, $isCatalogProduct=false, $orPosition=null, array $data=[])
$block
Definition: block.php:8