本文整理汇总了PHP中Magento\Framework\View\Element\AbstractBlock类的典型用法代码示例。如果您正苦于以下问题:PHP AbstractBlock类的具体用法?PHP AbstractBlock怎么用?PHP AbstractBlock使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了AbstractBlock类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: addErrorMessages
/**
* @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;
}
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:31,代码来源:ImportResult.php
示例2: _wrapEsi
/**
* 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);
}
开发者ID:Doability,项目名称:magento2dev,代码行数:14,代码来源:ProcessLayoutRenderElement.php
示例3: testGetCacheKeyByName
/**
* @return void
*/
public function testGetCacheKeyByName()
{
$nameInLayout = 'testBlock';
$this->block->setNameInLayout($nameInLayout);
$cacheKey = sha1($nameInLayout);
$this->assertEquals(AbstractBlock::CACHE_KEY_PREFIX . $cacheKey, $this->block->getCacheKey());
}
开发者ID:vv-team,项目名称:foodo,代码行数:10,代码来源:AbstractBlockTest.php
示例4: beforePushButtons
/**
* @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];
}
开发者ID:mcspronko,项目名称:magento2-order-buttons,代码行数:19,代码来源:Toolbar.php
示例5: aroundGetChildData
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;
}
开发者ID:outeredge,项目名称:magento-container-group-module,代码行数:15,代码来源:AbstractBlockPlugin.php
示例6: getToolbar
/**
* 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;
}
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:23,代码来源:Toolbar.php
示例7: pushButtons
/**
* {@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);
}
}
}
}
开发者ID:aiesh,项目名称:magento2,代码行数:21,代码来源:Toolbar.php
示例8: setUp
/**
* 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);
}
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:27,代码来源:ListActionTest.php
示例9: addBlock
/**
* 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;
}
开发者ID:opexsw,项目名称:magento2,代码行数:26,代码来源:Layout.php
示例10: insert
/**
* 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;
}
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:26,代码来源:AbstractBlock.php
示例11: generateLayoutUpdateXml
/**
* 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;
}
开发者ID:whoople,项目名称:magento2-testing,代码行数:40,代码来源:Instance.php
示例12: _wrapEsi
/**
* 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);
}
开发者ID:aiesh,项目名称:magento2,代码行数:11,代码来源:Observer.php
示例13: _prepareItem
/**
* @param AbstractBlock $renderer
* @return $this
*/
protected function _prepareItem(AbstractBlock $renderer)
{
$renderer->setPrintStatus(true);
return parent::_prepareItem($renderer);
}
开发者ID:aiesh,项目名称:magento2,代码行数:9,代码来源:Shipment.php
示例14: testExecute
/**
* @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']);
}
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:34,代码来源:ProcessLayoutRenderElementTest.php
示例15: add
/**
* 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);
}
}
开发者ID:shabbirvividads,项目名称:magento2,代码行数:18,代码来源:ActionPool.php
示例16: testGetRenderer
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'));
}
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:11,代码来源:RendererListTest.php
示例17: __construct
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);
}
开发者ID:hientruongbluecom,项目名称:cemagento2,代码行数:7,代码来源:ExchangeRate.php
示例18: _prepareLayout
/**
* 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();
}
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:33,代码来源:Config.php
示例19: __construct
/**
* @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);
}
开发者ID:BlackIkeEagle,项目名称:magento2-continuousphp,代码行数:14,代码来源:Gallery.php
示例20: __construct
/**
* 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;
}
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:16,代码来源:Block.php
注:本文中的Magento\Framework\View\Element\AbstractBlock类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论