/**
  * Replace the output of the block, containing ttl attribute, with ESI tag
  *
  * @param \Magento\Framework\View\Element\AbstractBlock $block
  * @param \Magento\Framework\View\Layout $layout
  * @return string
  */
 protected function _wrapEsi(\Magento\Framework\View\Element\AbstractBlock $block, \Magento\Framework\View\Layout $layout)
 {
     $url = $block->getUrl('page_cache/block/esi', ['blocks' => json_encode([$block->getNameInLayout()]), 'handles' => json_encode($layout->getUpdate()->getHandles())]);
     // Varnish does not support ESI over HTTPS must change to HTTP
     $url = substr($url, 0, 5) === 'https' ? 'http' . substr($url, 5) : $url;
     return sprintf('<esi:include src="%s" />', $url);
 }
 public function testSetGetNameInLayout()
 {
     // Basic setting/getting
     $this->assertEmpty($this->_block->getNameInLayout());
     $name = uniqid('name');
     $this->_block->setNameInLayout($name);
     $this->assertEquals($name, $this->_block->getNameInLayout());
     // Setting second time, along with the layout
     $layout = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('Magento\\Framework\\View\\LayoutInterface');
     $layout->createBlock('Magento\\Framework\\View\\Element\\Template', $name);
     $block = $layout->getBlock($name);
     $this->assertInstanceOf('Magento\\Framework\\View\\Element\\AbstractBlock', $block);
     $block->setNameInLayout($name);
     $this->assertInstanceOf('Magento\\Framework\\View\\Element\\AbstractBlock', $layout->getBlock($name));
     $this->assertEquals($name, $block->getNameInLayout());
     $this->assertTrue($layout->hasElement($name));
     $newName = 'new_name';
     $block->setNameInLayout($newName);
     $this->assertTrue($layout->hasElement($newName));
     $this->assertFalse($layout->hasElement($name));
 }
 public function aroundGetChildData(AbstractBlock $subject, callable $proceed, $alias, $key = '')
 {
     $returnValue = $proceed($alias, $key);
     if (null === $returnValue) {
         $layout = $subject->getLayout();
         if (!$layout) {
             return false;
         }
         $name = $layout->getChildName($subject->getNameInLayout(), $alias);
         if ($layout->isContainer($name)) {
             $returnValue = $layout->getElementProperty($name, $key);
         }
     }
     return $returnValue;
 }
Esempio n. 4
0
 /**
  * {@inheritdoc}
  */
 public function pushButtons(\Magento\Framework\View\Element\AbstractBlock $context, \Magento\Backend\Block\Widget\Button\ButtonList $buttonList)
 {
     foreach ($buttonList->getItems() as $buttons) {
         /** @var \Magento\Backend\Block\Widget\Button\Item $item */
         foreach ($buttons as $item) {
             $containerName = $context->getNameInLayout() . '-' . $item->getButtonKey();
             $container = $this->createContainer($context->getLayout(), $containerName, $item);
             if ($item->hasData('name')) {
                 $item->setData('element_name', $item->getName());
             }
             if ($container) {
                 $container->setContext($context);
                 $toolbar = $this->getToolbar($context, $item->getRegion());
                 $toolbar->setChild($item->getButtonKey(), $container);
             }
         }
     }
 }
Esempio n. 5
0
 /**
  * Add a block to registry, create new object if needed
  *
  * @param string|\Magento\Framework\View\Element\AbstractBlock $block
  * @param string $name
  * @param string $parent
  * @param string $alias
  * @return \Magento\Framework\View\Element\AbstractBlock
  */
 public function addBlock($block, $name = '', $parent = '', $alias = '')
 {
     $this->build();
     if ($block instanceof \Magento\Framework\View\Element\AbstractBlock) {
         $name = $name ?: $block->getNameInLayout();
     } else {
         $block = $this->_createBlock($block, $name);
     }
     $name = $this->structure->createStructuralElement($name, Element::TYPE_BLOCK, $name ?: get_class($block));
     $this->setBlock($name, $block);
     $block->setNameInLayout($name);
     if ($parent) {
         $this->structure->setAsChild($name, $parent, $alias);
     }
     $block->setLayout($this);
     return $block;
 }
 /**
  * Insert child element into specified position
  *
  * By default inserts as first element into children list
  *
  * @param \Magento\Framework\View\Element\AbstractBlock|string $element
  * @param string|int|null $siblingName
  * @param bool $after
  * @param string $alias
  * @return $this|bool
  */
 public function insert($element, $siblingName = 0, $after = true, $alias = '')
 {
     $layout = $this->getLayout();
     if (!$layout) {
         return false;
     }
     if ($element instanceof \Magento\Framework\View\Element\AbstractBlock) {
         $elementName = $element->getNameInLayout();
     } else {
         $elementName = $element;
     }
     $layout->setChild($this->_nameInLayout, $elementName, $alias);
     $layout->reorderChild($this->_nameInLayout, $elementName, $siblingName, $after);
     return $this;
 }
Esempio n. 7
0
 /**
  * Replace the output of the block, containing ttl attribute, with ESI tag
  *
  * @param \Magento\Framework\View\Element\AbstractBlock $block
  * @return string
  */
 protected function _wrapEsi(\Magento\Framework\View\Element\AbstractBlock $block)
 {
     $url = $block->getUrl('page_cache/block/esi', array('blocks' => json_encode(array($block->getNameInLayout())), 'handles' => json_encode($this->_helper->getActualHandles())));
     return sprintf('<esi:include src="%s" />', $url);
 }
Esempio n. 8
0
 /**
  * Run action defined in layout update
  *
  * @param \Magento\Framework\View\Element\AbstractBlock $block
  * @param string $methodName
  * @param array $actionArguments
  * @return void
  */
 protected function generateAction($block, $methodName, $actionArguments)
 {
     $profilerKey = 'BLOCK_ACTION:' . $block->getNameInLayout() . '>' . $methodName;
     \Magento\Framework\Profiler::start($profilerKey);
     $args = $this->evaluateArguments($actionArguments);
     call_user_func_array([$block, $methodName], $args);
     \Magento\Framework\Profiler::stop($profilerKey);
 }
 /**
  * Replace the output of the block, containing ttl attribute, with ESI tag
  *
  * @param \Magento\Framework\View\Element\AbstractBlock $block
  * @param \Magento\Framework\View\Layout $layout
  * @return string
  */
 protected function _wrapEsi(\Magento\Framework\View\Element\AbstractBlock $block, \Magento\Framework\View\Layout $layout)
 {
     $url = $block->getUrl('page_cache/block/esi', ['blocks' => json_encode([$block->getNameInLayout()]), 'handles' => json_encode($layout->getUpdate()->getHandles())]);
     return sprintf('<esi:include src="%s" />', $url);
 }
Esempio n. 10
0
 /**
  * Set specified block as an anonymous child to specified container
  *
  * The block will be moved to the container from previous parent after all other elements
  *
  * @param \Magento\Framework\View\Element\AbstractBlock $block
  * @param string $containerName
  * @return $this
  */
 protected function moveBlockToContainer(View\Element\AbstractBlock $block, $containerName)
 {
     $this->layout->setChild($containerName, $block->getNameInLayout(), '');
     return $this;
 }
Esempio n. 11
0
 /**
  * Render Block
  *
  * @param \Magento\Framework\View\Element\AbstractBlock $link
  * @return string
  */
 public function renderLink(\Magento\Framework\View\Element\AbstractBlock $link)
 {
     return $this->_layout->renderElement($link->getNameInLayout());
 }
 /**
  * Set specified block as an anonymous child to specified container
  *
  * The block will be moved to the container from previous parent after all other elements
  *
  * @param \Magento\Framework\View\Element\AbstractBlock $block
  * @param string $containerName
  * @return $this
  */
 private function _moveBlockToContainer(\Magento\Framework\View\Element\AbstractBlock $block, $containerName)
 {
     $this->_view->getLayout()->setChild($containerName, $block->getNameInLayout(), '');
     return $this;
 }
Esempio n. 13
0
 /**
  * Add a block to registry, create new object if needed
  *
  * @param string|\Magento\Framework\View\Element\AbstractBlock $block
  * @param string $name
  * @param string $parent
  * @param string $alias
  * @return \Magento\Framework\View\Element\AbstractBlock
  */
 public function addBlock($block, $name = '', $parent = '', $alias = '')
 {
     if (empty($name) && $block instanceof \Magento\Framework\View\Element\AbstractBlock) {
         $name = $block->getNameInLayout();
     }
     $name = $this->_createStructuralElement($name, Element::TYPE_BLOCK, $name ?: (is_object($block) ? get_class($block) : $block));
     if ($parent) {
         $this->_structure->setAsChild($name, $parent, $alias);
     }
     return $this->_createBlock($block, $name);
 }
Esempio n. 14
0
/**
 * 2016-11-30
 * Наивное $e->getParentBlock()->getNameInLayout() некорректно,
 * потому что родительским элементом для $e может быть не только блок,
 * но и контейнер, и тогда $e->getParentBlock() вернёт false.
 * @param AbstractBlock|string $e
 * @return string|null
 */
function df_parent_name($e)
{
    return df_ftn(df_layout()->getParentName($e instanceof AbstractBlock ? $e->getNameInLayout() : $e));
}
Esempio n. 15
0
 /**
  * @param AbstractBlock $block
  *
  * @return string
  */
 protected function _getBlockNamePath(AbstractBlock $block)
 {
     $layout = $block->getLayout();
     $blockName = $block->getNameInLayout();
     $path = $this->_getElementPath($layout, $blockName);
     return isset($path) ? $path . " / " . $blockName : $blockName;
 }
Esempio n. 16
0
 public function afterToHtml(\Magento\Framework\View\Element\AbstractBlock $subject, $result)
 {
     $this->agent->addCustomParameter('block::' . $subject->getNameInLayout(), 1);
     return $result;
 }