/**
  * @param \Magento\Framework\View\Element\AbstractBlock $resultBlock
  * @param ProcessingErrorAggregatorInterface $errorAggregator
  * @return $this
  */
 protected function addErrorMessages(\Magento\Framework\View\Element\AbstractBlock $resultBlock, ProcessingErrorAggregatorInterface $errorAggregator)
 {
     if ($errorAggregator->getErrorsCount()) {
         $message = '';
         $counter = 0;
         foreach ($this->getErrorMessages($errorAggregator) as $error) {
             $message .= ++$counter . '. ' . $error . '<br>';
             if ($counter >= self::LIMIT_ERRORS_MESSAGE) {
                 break;
             }
         }
         if ($errorAggregator->hasFatalExceptions()) {
             foreach ($this->getSystemExceptions($errorAggregator) as $error) {
                 $message .= $error->getErrorMessage() . ' <a href="#" onclick="$(this).next().show();$(this).hide();return false;">' . __('Show more') . '</a><div style="display:none;">' . __('Additional data') . ': ' . $error->getErrorDescription() . '</div>';
             }
         }
         try {
             $resultBlock->addNotice('<strong>' . __('Following Error(s) has been occurred during importing process:') . '</strong><br>' . '<div class="import-error-wrapper">' . __('Only first 100 errors are displayed here. ') . '<a href="' . $this->createDownloadUrlImportHistoryFile($this->createErrorReport($errorAggregator)) . '">' . __('Download full report') . '</a><br>' . '<div class="import-error-list">' . $message . '</div></div>');
         } catch (\Exception $e) {
             foreach ($this->getErrorMessages($errorAggregator) as $errorMessage) {
                 $resultBlock->addError($errorMessage);
             }
         }
     }
     return $this;
 }
 /**
  * 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);
 }
 /**
  * @param bool $cacheState
  * @param bool $varnishIsEnabled
  * @param bool $scopeIsPrivate
  * @param int|null $blockTtl
  * @param string $expectedOutput
  * @dataProvider processLayoutRenderDataProvider
  */
 public function testExecute($cacheState, $varnishIsEnabled, $scopeIsPrivate, $blockTtl, $expectedOutput)
 {
     $eventMock = $this->getMock('Magento\\Framework\\Event', ['getLayout', 'getElementName', 'getTransport'], [], '', false);
     $this->_observerMock->expects($this->once())->method('getEvent')->will($this->returnValue($eventMock));
     $eventMock->expects($this->once())->method('getLayout')->will($this->returnValue($this->_layoutMock));
     $this->_configMock->expects($this->any())->method('isEnabled')->will($this->returnValue($cacheState));
     if ($cacheState) {
         $eventMock->expects($this->once())->method('getElementName')->will($this->returnValue('blockName'));
         $eventMock->expects($this->once())->method('getTransport')->will($this->returnValue($this->_transport));
         $this->_layoutMock->expects($this->once())->method('isCacheable')->will($this->returnValue(true));
         $this->_layoutMock->expects($this->any())->method('getUpdate')->will($this->returnSelf());
         $this->_layoutMock->expects($this->any())->method('getHandles')->will($this->returnValue([]));
         $this->_layoutMock->expects($this->once())->method('getBlock')->will($this->returnValue($this->_blockMock));
         if ($varnishIsEnabled) {
             $this->_blockMock->expects($this->once())->method('getData')->with('ttl')->will($this->returnValue($blockTtl));
             $this->_blockMock->expects($this->any())->method('getUrl')->will($this->returnValue('page_cache/block/wrapesi/with/handles/and/other/stuff'));
         }
         if ($scopeIsPrivate) {
             $this->_blockMock->expects($this->once())->method('getNameInLayout')->will($this->returnValue('testBlockName'));
             $this->_blockMock->expects($this->once())->method('isScopePrivate')->will($this->returnValue($scopeIsPrivate));
         }
         $this->_configMock->expects($this->any())->method('getType')->will($this->returnValue($varnishIsEnabled));
     }
     $this->_model->execute($this->_observerMock);
     $this->assertEquals($expectedOutput, $this->_transport['output']);
 }
Example #4
0
 /**
  * @return void
  */
 public function testGetCacheKeyByName()
 {
     $nameInLayout = 'testBlock';
     $this->block->setNameInLayout($nameInLayout);
     $cacheKey = sha1($nameInLayout);
     $this->assertEquals(AbstractBlock::CACHE_KEY_PREFIX . $cacheKey, $this->block->getCacheKey());
 }
Example #5
0
 /**
  * Add button
  *
  * @param string $key
  * @param array $data
  * @param UiComponentInterface $view
  * @return void
  */
 public function add($key, array $data, UiComponentInterface $view)
 {
     $data['id'] = isset($data['id']) ? $data['id'] : $key;
     if ($this->toolbarBlock !== false) {
         $this->items[$key] = $this->itemFactory->create();
         $this->items[$key]->setData($data);
         $container = $this->createContainer($key, $view);
         $this->toolbarBlock->setChild($key, $container);
     }
 }
 public function testGetRenderer()
 {
     $this->blockMock->expects($this->any())->method('setRenderedBlock')->will($this->returnValue($this->blockMock));
     $this->blockMock->expects($this->any())->method('getTemplate')->will($this->returnValue('template'));
     $this->blockMock->expects($this->any())->method('setTemplate')->will($this->returnValue($this->blockMock));
     $this->layoutMock->expects($this->any())->method('getChildName')->will($this->returnValue(true));
     /** During the first call cache will be generated */
     $this->assertInstanceOf('\\Magento\\Framework\\View\\Element\\BlockInterface', $this->renderList->getRenderer('type', null, null));
     /** Cached value should be returned during second call */
     $this->assertInstanceOf('\\Magento\\Framework\\View\\Element\\BlockInterface', $this->renderList->getRenderer('type', null, 'renderer_template'));
 }
 /**
  * @param ToolbarContext $toolbar
  * @param AbstractBlock $context
  * @param ButtonList $buttonList
  * @return array
  */
 public function beforePushButtons(ToolbarContext $toolbar, \Magento\Framework\View\Element\AbstractBlock $context, \Magento\Backend\Block\Widget\Button\ButtonList $buttonList)
 {
     if (!$context instanceof \Magento\Sales\Block\Adminhtml\Order\View) {
         return [$context, $buttonList];
     }
     $buttonList->update('order_edit', 'class', 'edit');
     $buttonList->update('order_invoice', 'class', 'invoice primary');
     $buttonList->update('order_invoice', 'sort_order', (count($buttonList->getItems()) + 1) * 10);
     $buttonList->add('order_review', ['label' => __('Review'), 'onclick' => 'setLocation(\'' . $context->getUrl('sales/*/review') . '\')', 'class' => 'review']);
     $buttonList->remove('order_hold');
     $buttonList->remove('send_notification');
     return [$context, $buttonList];
 }
 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;
 }
Example #9
0
 /**
  * Return button parent block
  *
  * @param \Magento\Framework\View\Element\AbstractBlock $context
  * @param string $region
  * @return \Magento\Backend\Block\Template
  */
 protected function getToolbar(\Magento\Framework\View\Element\AbstractBlock $context, $region)
 {
     $parent = null;
     $layout = $context->getLayout();
     if (!$region || $region == 'header' || $region == 'footer') {
         $parent = $context;
     } elseif ($region == 'toolbar') {
         $parent = $layout->getBlock('page.actions.toolbar');
     } else {
         $parent = $layout->getBlock($region);
     }
     if ($parent) {
         return $parent;
     }
     return $context;
 }
 public function __construct(\Magento\Framework\View\Element\Context $context, \Magento\Framework\HTTP\ZendClientFactory $clientFactory, \Psr\Log\LoggerInterface $logger, array $data = [])
 {
     $this->_isScopePrivate = true;
     $this->_clientFactory = $clientFactory;
     $this->_logger = $logger;
     parent::__construct($context, $data);
 }
Example #11
0
 /**
  * Include RequireJs configuration as an asset on the page
  *
  * @return $this
  */
 protected function _prepareLayout()
 {
     $requireJsConfig = $this->fileManager->createRequireJsConfigAsset();
     $requireJsMixinsConfig = $this->fileManager->createRequireJsMixinsAsset();
     $assetCollection = $this->pageConfig->getAssetCollection();
     $after = RequireJsConfig::REQUIRE_JS_FILE_NAME;
     if ($this->minification->isEnabled('js')) {
         $minResolver = $this->fileManager->createMinResolverAsset();
         $assetCollection->insert($minResolver->getFilePath(), $minResolver, $after);
         $after = $minResolver->getFilePath();
     }
     if ($this->bundleConfig->isBundlingJsFiles()) {
         $bundleAssets = $this->fileManager->createBundleJsPool();
         $staticAsset = $this->fileManager->createStaticJsAsset();
         /** @var \Magento\Framework\View\Asset\File $bundleAsset */
         if (!empty($bundleAssets) && $staticAsset !== false) {
             $bundleAssets = array_reverse($bundleAssets);
             foreach ($bundleAssets as $bundleAsset) {
                 $assetCollection->insert($bundleAsset->getFilePath(), $bundleAsset, $after);
             }
             $assetCollection->insert($staticAsset->getFilePath(), $staticAsset, reset($bundleAssets)->getFilePath());
             $after = $staticAsset->getFilePath();
         }
     }
     $assetCollection->insert($requireJsConfig->getFilePath(), $requireJsConfig, $after);
     $assetCollection->insert($requireJsMixinsConfig->getFilePath(), $requireJsMixinsConfig, $after);
     return parent::_prepareLayout();
 }
 /**
  * @param \Magento\Framework\View\Element\Context $context
  * @param \Magento\Store\Model\StoreManagerInterface $storeManager
  * @param Registry $registry
  * @param \Magento\Framework\Data\Form $form
  * @param array $data
  */
 public function __construct(\Magento\Framework\View\Element\Context $context, \Magento\Store\Model\StoreManagerInterface $storeManager, Registry $registry, \Magento\Framework\Data\Form $form, $data = [])
 {
     $this->storeManager = $storeManager;
     $this->registry = $registry;
     $this->form = $form;
     parent::__construct($context, $data);
 }
Example #13
0
 /**
  * Construct
  *
  * @param \Magento\Framework\View\Element\Context $context
  * @param \Magento\Cms\Model\Template\FilterProvider $filterProvider
  * @param \Magento\Store\Model\StoreManagerInterface $storeManager
  * @param \Magento\Cms\Model\BlockFactory $blockFactory
  * @param array $data
  */
 public function __construct(\Magento\Framework\View\Element\Context $context, \Magento\Cms\Model\Template\FilterProvider $filterProvider, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Cms\Model\BlockFactory $blockFactory, array $data = [])
 {
     parent::__construct($context, $data);
     $this->_filterProvider = $filterProvider;
     $this->_storeManager = $storeManager;
     $this->_blockFactory = $blockFactory;
 }
Example #14
0
 /**
  * @param \Magento\Framework\View\Element\Context $context
  * @param \Magento\Framework\Data\FormFactory $formFactory
  * @param \Magento\Framework\Data\Form\Element\Factory $elementFactory
  * @param \Magento\Paypal\Model\StandardFactory $paypalStandardFactory
  * @param \Magento\Framework\Math\Random $mathRandom
  * @param array $data
  */
 public function __construct(\Magento\Framework\View\Element\Context $context, \Magento\Framework\Data\FormFactory $formFactory, \Magento\Framework\Data\Form\Element\Factory $elementFactory, \Magento\Paypal\Model\StandardFactory $paypalStandardFactory, \Magento\Framework\Math\Random $mathRandom, array $data = array())
 {
     $this->_formFactory = $formFactory;
     $this->_elementFactory = $elementFactory;
     $this->_paypalStandardFactory = $paypalStandardFactory;
     $this->mathRandom = $mathRandom;
     parent::__construct($context, $data);
 }
Example #15
0
 /**
  * @param RssModel $rssModel
  * @param Url $urlModel
  * @param CollectionFactory $articleCollectionFactory
  * @param StoreManagerInterface $storeManager
  * @param Context $context
  * @param array $data
  */
 public function __construct(RssModel $rssModel, Url $urlModel, CollectionFactory $articleCollectionFactory, StoreManagerInterface $storeManager, Context $context, array $data = [])
 {
     $this->rssModel = $rssModel;
     $this->urlModel = $urlModel;
     $this->articleCollectionFactory = $articleCollectionFactory;
     $this->storeManager = $storeManager;
     parent::__construct($context, $data);
 }
Example #16
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($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);
             }
         }
     }
 }
Example #17
0
 /**
  * Constructor
  *
  * @param \Magento\Framework\View\Element\Context $context
  * @param ElementFactory $elementFactory
  * @param \Magento\Directory\Model\CountryFactory $countryFactory
  * @param \Magento\Customer\Api\AddressMetadataInterface $metadataService
  * @param Mapper $addressMapper
  * @param array $data
  */
 public function __construct(\Magento\Framework\View\Element\Context $context, ElementFactory $elementFactory, \Magento\Directory\Model\CountryFactory $countryFactory, \Magento\Customer\Api\AddressMetadataInterface $metadataService, Mapper $addressMapper, array $data = [])
 {
     $this->_elementFactory = $elementFactory;
     $this->_countryFactory = $countryFactory;
     $this->_addressMetadataService = $metadataService;
     $this->addressMapper = $addressMapper;
     parent::__construct($context, $data);
     $this->_isScopePrivate = true;
 }
Example #18
0
 /**
  * Constructor
  *
  * @param \Magento\Framework\View\Element\Context $context
  * @param ElementFactory $elementFactory
  * @param \Magento\Directory\Model\CountryFactory $countryFactory ,
  * @param \Magento\Customer\Model\Address\Converter $addressConverter
  * @param \Magento\Customer\Service\V1\CustomerMetadataServiceInterface $metadataService
  * @param array $data
  */
 public function __construct(\Magento\Framework\View\Element\Context $context, ElementFactory $elementFactory, \Magento\Directory\Model\CountryFactory $countryFactory, \Magento\Customer\Model\Address\Converter $addressConverter, \Magento\Customer\Service\V1\CustomerMetadataServiceInterface $metadataService, array $data = array())
 {
     $this->_elementFactory = $elementFactory;
     $this->_addressConverter = $addressConverter;
     $this->_countryFactory = $countryFactory;
     $this->_metadataService = $metadataService;
     parent::__construct($context, $data);
     $this->_isScopePrivate = true;
 }
 /**
  * Set up test
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 protected function setUp()
 {
     $this->contextMock = $this->getMock('Magento\\Backend\\App\\Action\\Context', ['getAuthorization', 'getSession', 'getActionFlag', 'getAuth', 'getView', 'getHelper', 'getBackendUrl', 'getFormKeyValidator', 'getLocaleResolver', 'getCanUseBaseUrl', 'getRequest', 'getResponse', 'getObjectManager', 'getMessageManager'], [], '', false);
     $this->response = $this->getMock('Magento\\Framework\\App\\ResponseInterface', ['setRedirect', 'sendResponse'], [], '', false);
     $this->request = $this->getMockForAbstractClass('\\Magento\\Framework\\App\\RequestInterface', ['getParam', 'getRequest'], '', false);
     $this->view = $this->getMock('\\Magento\\Framework\\App\\ViewInterface', ['loadLayout', 'getPage', 'getConfig', 'getTitle', 'loadLayoutUpdates', 'renderLayout', 'getDefaultLayoutHandle', 'generateLayoutXml', 'addPageLayoutHandles', 'generateLayoutBlocks', 'getLayout', 'addActionLayoutHandles', 'setIsLayoutLoaded', 'isLayoutLoaded'], [], '', false);
     $this->block = $this->getMock('\\Magento\\Framework\\View\\Element\\AbstractBlock', ['setActive', 'getMenuModel'], [], '', false);
     $this->layout = $this->getMockForAbstractClass('\\Magento\\Framework\\View\\LayoutInterface', ['getBlock'], '', false);
     $this->menu = $this->getMock('\\Magento\\Backend\\Model\\Menu', ['getParentItems'], [], '', false);
     $this->items = $this->getMock('\\Magento\\Backend\\Model\\Menu\\Item', ['getParentItems'], [], '', false);
     $this->contextMock->expects($this->any())->method("getRequest")->willReturn($this->request);
     $this->contextMock->expects($this->any())->method("getResponse")->willReturn($this->response);
     $this->contextMock->expects($this->any())->method('getView')->will($this->returnValue($this->view));
     $this->page = $this->getMock('\\Magento\\Framework\\View\\Result\\Page', ['getConfig'], [], '', false);
     $this->config = $this->getMock('\\Magento\\Framework\\View\\Result\\Page', ['getTitle'], [], '', false);
     $this->title = $this->getMock('\\Title', ['prepend'], [], '', false);
     $this->block->expects($this->any())->method('setActive')->will($this->returnValue(1));
     $this->view->expects($this->any())->method('getLayout')->will($this->returnValue($this->layout));
     $this->layout->expects($this->any())->method('getBlock')->with('menu')->will($this->returnValue($this->block));
     $this->block->expects($this->any())->method('getMenuModel')->will($this->returnValue($this->menu));
     $this->menu->expects($this->any())->method('getParentItems')->will($this->returnValue($this->items));
     $this->object = new \Magento\Indexer\Controller\Adminhtml\Indexer\ListAction($this->contextMock);
 }
Example #20
0
 /**
  * {@inheritdoc}
  */
 protected function _toHtml()
 {
     $item = $this->getButtonItem();
     $context = $this->getContext();
     if ($item && $context && $context->canRender($item)) {
         $data = $item->getData();
         $blockClassName = isset($data['class_name']) ? $data['class_name'] : null;
         $buttonName = $this->getContext()->getNameInLayout() . '-' . $item->getId() . '-button';
         $block = $this->createButton($buttonName, $blockClassName);
         $block->setData($data);
         return $block->toHtml();
     }
     return parent::_toHtml();
 }
Example #21
0
 /**
  * Include RequireJs configuration as an asset on the page
  *
  * @return $this
  */
 protected function _prepareLayout()
 {
     $requireJsConfig = $this->fileManager->createRequireJsConfigAsset();
     $assetCollection = $this->pageConfig->getAssetCollection();
     $assetCollection->insert($requireJsConfig->getFilePath(), $requireJsConfig, RequireJsConfig::REQUIRE_JS_FILE_NAME);
     if ($this->bundleConfig->isBundlingJsFiles()) {
         $bundleAssets = $this->fileManager->createBundleJsPool();
         $staticAsset = $this->fileManager->createStaticJsAsset();
         /** @var \Magento\Framework\View\Asset\File $bundleAsset */
         if (!empty($bundleAssets) && $staticAsset !== false) {
             $bundleAssets = array_reverse($bundleAssets);
             foreach ($bundleAssets as $bundleAsset) {
                 $assetCollection->insert($bundleAsset->getFilePath(), $bundleAsset, RequireJsConfig::REQUIRE_JS_FILE_NAME);
             }
             $assetCollection->insert($staticAsset->getFilePath(), $staticAsset, RequireJsConfig::CONFIG_FILE_NAME);
         }
     }
     return parent::_prepareLayout();
 }
Example #22
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;
 }
Example #23
0
 /**
  * Prepare global layout
  *
  * @return $this
  */
 protected function _prepareLayout()
 {
     $page = $this->getPage();
     // show breadcrumbs
     if ($this->_scopeConfig->getValue('web/default/show_cms_breadcrumbs', \Magento\Store\Model\ScopeInterface::SCOPE_STORE) && ($breadcrumbs = $this->getLayout()->getBlock('breadcrumbs')) && $page->getIdentifier() !== $this->_scopeConfig->getValue('web/default/cms_home_page', \Magento\Store\Model\ScopeInterface::SCOPE_STORE) && $page->getIdentifier() !== $this->_scopeConfig->getValue('web/default/cms_no_route', \Magento\Store\Model\ScopeInterface::SCOPE_STORE)) {
         $breadcrumbs->addCrumb('home', array('label' => __('Home'), 'title' => __('Go to Home Page'), 'link' => $this->_storeManager->getStore()->getBaseUrl()));
         $breadcrumbs->addCrumb('cms_page', array('label' => $page->getTitle(), 'title' => $page->getTitle()));
     }
     $this->pageConfig->addBodyClass('cms-' . $page->getIdentifier());
     $head = $this->getLayout()->getBlock('head');
     if ($head) {
         $head->setTitle($page->getTitle());
         $head->setKeywords($page->getMetaKeywords());
         $head->setDescription($page->getMetaDescription());
     }
     $pageMainTitle = $this->getLayout()->getBlock('page.main.title');
     if ($pageMainTitle) {
         // Setting empty page title if content heading is absent
         $cmsTitle = $page->getContentHeading() ?: ' ';
         $pageMainTitle->setPageTitle($this->escapeHtml($cmsTitle));
     }
     return parent::_prepareLayout();
 }
Example #24
0
 /**
  * {@inheritdoc}
  */
 protected function _construct()
 {
     $this->setCacheKey('rss_catalog_salesrule_' . $this->getStoreId() . '_' . $this->getCustomerGroupId());
     parent::_construct();
 }
 /**
  * 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;
 }
Example #26
0
 /**
  * Generate layout update xml
  *
  * @param string $container
  * @param string $templatePath
  * @return string
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function generateLayoutUpdateXml($container, $templatePath = '')
 {
     $templateFilename = $this->_viewFileSystem->getTemplateFileName($templatePath, ['area' => $this->getArea(), 'themeId' => $this->getThemeId(), 'module' => \Magento\Framework\View\Element\AbstractBlock::extractModuleName($this->getType())]);
     if (!$this->getId() && !$this->isCompleteToCreate() || $templatePath && !is_readable($templateFilename)) {
         return '';
     }
     $parameters = $this->getWidgetParameters();
     $xml = '<body><referenceContainer name="' . $container . '">';
     $template = '';
     if (isset($parameters['template'])) {
         unset($parameters['template']);
     }
     if ($templatePath) {
         $template = ' template="' . $templatePath . '"';
     }
     $hash = $this->mathRandom->getUniqueHash();
     $xml .= '<block class="' . $this->getType() . '" name="' . $hash . '"' . $template . '>';
     foreach ($parameters as $name => $value) {
         if ($name == 'conditions') {
             $name = 'conditions_encoded';
             $value = $this->conditionsHelper->encode($value);
         } elseif (is_array($value)) {
             $value = implode(',', $value);
         }
         if ($name && strlen((string) $value)) {
             $xml .= '<action method="setData">' . '<argument name="name" xsi:type="string">' . $name . '</argument>' . '<argument name="value" xsi:type="string">' . $this->_escaper->escapeHtml($value) . '</argument>' . '</action>';
         }
     }
     $xml .= '</block></referenceContainer></body>';
     return $xml;
 }
Example #27
0
 /**
  * Include RequireJs configuration as an asset on the page
  *
  * @return $this
  */
 protected function _prepareLayout()
 {
     $this->addInlineTranslationConfig();
     return parent::_prepareLayout();
 }
Example #28
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);
 }
Example #29
0
 /**
  * @param AbstractBlock $renderer
  * @return $this
  */
 protected function _prepareItem(AbstractBlock $renderer)
 {
     $renderer->setPrintStatus(true);
     return parent::_prepareItem($renderer);
 }
 /**
  * @return void
  */
 protected function _construct()
 {
     $this->setCacheKey('rss_blog_categories_store_' . $this->getStoreId());
     parent::_construct();
 }