本文整理匯總了PHP中Magento\Framework\View\LayoutFactory::create方法的典型用法代碼示例。如果您正苦於以下問題:PHP LayoutFactory::create方法的具體用法?PHP LayoutFactory::create怎麽用?PHP LayoutFactory::create使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Magento\Framework\View\LayoutFactory
的用法示例。
在下文中一共展示了LayoutFactory::create方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: executeInternal
/**
* Attributes validation action
*
* @return \Magento\Framework\Controller\ResultInterface
*/
public function executeInternal()
{
$response = $this->_objectManager->create('Magento\\Framework\\DataObject');
$response->setError(false);
$attributesData = $this->getRequest()->getParam('attributes', []);
$data = $this->_objectManager->create('Magento\\Catalog\\Model\\Product');
try {
if ($attributesData) {
foreach ($attributesData as $attributeCode => $value) {
$attribute = $this->_objectManager->get('Magento\\Eav\\Model\\Config')->getAttribute('catalog_product', $attributeCode);
if (!$attribute->getAttributeId()) {
unset($attributesData[$attributeCode]);
continue;
}
$data->setData($attributeCode, $value);
$attribute->getBackend()->validate($data);
}
}
} catch (\Magento\Eav\Model\Entity\Attribute\Exception $e) {
$response->setError(true);
$response->setAttribute($e->getAttributeCode());
$response->setMessage($e->getMessage());
} catch (\Magento\Framework\Exception\LocalizedException $e) {
$response->setError(true);
$response->setMessage($e->getMessage());
} catch (\Exception $e) {
$this->messageManager->addException($e, __('Something went wrong while updating the product(s) attributes.'));
$layout = $this->layoutFactory->create();
$layout->initMessages();
$response->setError(true);
$response->setHtmlMessage($layout->getMessagesBlock()->getGroupedHtml());
}
return $this->resultJsonFactory->create()->setJsonData($response->toJson());
}
示例2: execute
/**
* @return \Magento\Framework\Controller\ResultInterface
*/
public function execute()
{
$response = new \Magento\Framework\Object();
$response->setError(false);
$attributeCode = $this->getRequest()->getParam('attribute_code');
$frontendLabel = $this->getRequest()->getParam('frontend_label');
$attributeCode = $attributeCode ?: $this->generateCode($frontendLabel[0]);
$attributeId = $this->getRequest()->getParam('attribute_id');
$attribute = $this->_objectManager->create('Magento\\Catalog\\Model\\Resource\\Eav\\Attribute')->loadByCode($this->_entityTypeId, $attributeCode);
if ($attribute->getId() && !$attributeId) {
if (strlen($this->getRequest()->getParam('attribute_code'))) {
$response->setAttributes(['attribute_code' => __('An attribute with this code already exists.')]);
} else {
$response->setAttributes(['attribute_label' => __('Attribute with the same code (%1) already exists.', $attributeCode)]);
}
$response->setError(true);
}
if ($this->getRequest()->has('new_attribute_set_name')) {
$setName = $this->getRequest()->getParam('new_attribute_set_name');
/** @var $attributeSet \Magento\Eav\Model\Entity\Attribute\Set */
$attributeSet = $this->_objectManager->create('Magento\\Eav\\Model\\Entity\\Attribute\\Set');
$attributeSet->setEntityTypeId($this->_entityTypeId)->load($setName, 'attribute_set_name');
if ($attributeSet->getId()) {
$setName = $this->_objectManager->get('Magento\\Framework\\Escaper')->escapeHtml($setName);
$this->messageManager->addError(__('Attribute Set with name \'%1\' already exists.', $setName));
$layout = $this->layoutFactory->create();
$layout->initMessages();
$response->setError(true);
$response->setHtmlMessage($layout->getMessagesBlock()->getGroupedHtml());
}
}
return $this->resultJsonFactory->create()->setJsonData($response->toJson());
}
示例3: getStatusHtml
/**
* @return string
*/
protected function getStatusHtml()
{
$layout = $this->layoutFactory->create();
/** @var \Tobai\GeoIp2\Block\Adminhtml\System\Config\Status $statusBlock */
$statusBlock = $layout->createBlock('Tobai\\GeoIp2\\Block\\Adminhtml\\System\\Config\\Status');
return $statusBlock->getDbStatus();
}
示例4: execute
/**
* @return \Magento\Framework\Controller\Result\Raw
*/
public function execute()
{
$layout = $this->layoutFactory->create();
/** @var \Magento\Framework\Controller\Result\Raw $resultRaw */
$resultRaw = $this->resultFactory->create(ResultFactory::TYPE_RAW);
$resultRaw->setContents($layout->createBlock('Magento\\Review\\Block\\Adminhtml\\Rating\\Detailed')->setIndependentMode()->toHtml());
return $resultRaw;
}
示例5: execute
/**
* Grid with Google Content items
*
* @return \Magento\Framework\Controller\Result\Raw
*/
public function execute()
{
/** @var \Magento\Framework\Controller\Result\Raw $resultRaw */
$resultRaw = $this->resultFactory->create(\Magento\Framework\Controller\ResultFactory::TYPE_RAW);
/** @var \Magento\GoogleShopping\Block\Adminhtml\Items\Item $block */
$block = $this->layoutFactory->create()->createBlock('Magento\\GoogleShopping\\Block\\Adminhtml\\Items\\Item');
return $resultRaw->setContents($block->setIndex($this->getRequest()->getParam('index'))->toHtml());
}
示例6: executeInternal
/**
* @return \Magento\Framework\Controller\Result\Raw
*/
public function executeInternal()
{
$layout = $this->layoutFactory->create();
/** @var \Magento\Framework\Controller\Result\Raw $resultRaw */
$resultRaw = $this->resultFactory->create(ResultFactory::TYPE_RAW);
$resultRaw->setContents($layout->createBlock('Magento\Review\Block\Adminhtml\Grid')->toHtml());
return $resultRaw;
}
示例7: testConstructorStructure
public function testConstructorStructure()
{
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
$structure = $objectManager->get('Magento\\Framework\\View\\Layout\\Data\\Structure');
$structure->createElement('test.container', []);
/** @var $layout \Magento\Framework\View\LayoutInterface */
$layout = $this->layoutFactory->create(['structure' => $structure]);
$this->assertTrue($layout->hasElement('test.container'));
}
示例8: _getLayoutModel
/**
* Prepare a layout model with pre-loaded fixture of an update XML
*
* @param string $fixtureFile
* @return \Magento\Framework\View\LayoutInterface
*/
protected function _getLayoutModel($fixtureFile)
{
$this->objectManager->get('Magento\\Framework\\App\\Cache\\Type\\Layout')->clean();
$layout = $this->layoutFactory->create();
/** @var $xml \Magento\Framework\View\Layout\Element */
$xml = simplexml_load_file(__DIR__ . "/_files/layout_directives_test/{$fixtureFile}", 'Magento\\Framework\\View\\Layout\\Element');
$layout->loadString($xml->asXml());
$layout->generateElements();
return $layout;
}
示例9: execute
/**
* Get specified tab grid
*
* @return \Magento\Framework\Controller\Result\Raw
*/
public function execute()
{
$this->_view->getPage()->getConfig()->getTitle()->prepend(__('Products'));
$this->productBuilder->build($this->getRequest());
$block = $this->getRequest()->getParam('gridOnlyBlock');
$blockClassSuffix = str_replace(' ', '_', ucwords(str_replace('_', ' ', $block)));
/** @var \Magento\Framework\Controller\Result\Raw $resultRaw */
$resultRaw = $this->resultRawFactory->create();
return $resultRaw->setContents($this->layoutFactory->create()->createBlock('Magento\\Catalog\\Block\\Adminhtml\\Product\\Edit\\Tab\\' . $blockClassSuffix)->toHtml());
}
示例10: execute
/**
* WYSIWYG editor action for ajax request
*
* @return \Magento\Framework\Controller\Result\Raw
*/
public function execute()
{
$elementId = $this->getRequest()->getParam('element_id', md5(microtime()));
$storeId = $this->getRequest()->getParam('store_id', 0);
$storeMediaUrl = $this->_objectManager->get('Magento\\Store\\Model\\StoreManagerInterface')->getStore($storeId)->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA);
$content = $this->layoutFactory->create()->createBlock('Magento\\Catalog\\Block\\Adminhtml\\Helper\\Form\\Wysiwyg\\Content', '', ['data' => ['editor_element_id' => $elementId, 'store_id' => $storeId, 'store_media_url' => $storeMediaUrl]]);
/** @var \Magento\Framework\Controller\Result\Raw $resultRaw */
$resultRaw = $this->resultRawFactory->create();
return $resultRaw->setContents($content->toHtml());
}
示例11: execute
/**
* Generate order history for ajax request
*
* @return \Magento\Framework\Controller\Result\Raw
*/
public function execute()
{
$this->_initOrder();
$layout = $this->layoutFactory->create();
$html = $layout->createBlock('Magento\\Sales\\Block\\Adminhtml\\Order\\View\\Tab\\History')->toHtml();
$this->_translateInline->processResponseBody($html);
/** @var \Magento\Framework\Controller\Result\Raw $resultRaw */
$resultRaw = $this->resultRawFactory->create();
$resultRaw->setContents($html);
return $resultRaw;
}
示例12: execute
/**
* Chooser Source action
*
* @return \Magento\Framework\Controller\Result\Raw
*/
public function execute()
{
$uniqId = $this->getRequest()->getParam('uniq_id');
/** @var \Magento\Framework\View\Layout $layout */
$layout = $this->layoutFactory->create();
$pagesGrid = $layout->createBlock('Magento\\Cms\\Block\\Adminhtml\\Page\\Widget\\Chooser', '', ['data' => ['id' => $uniqId]]);
$html = $pagesGrid->toHtml();
/** @var \Magento\Framework\Controller\Result\Raw $resultRaw */
$resultRaw = $this->resultRawFactory->create();
return $resultRaw->setContents($html);
}
示例13: execute
/**
* @return \Magento\Framework\Controller\Result\Raw
*/
public function execute()
{
$output = '';
$blockTab = $this->getRequest()->getParam('block');
$blockClassSuffix = str_replace(' ', '\\', ucwords(str_replace('_', ' ', $blockTab)));
if (in_array($blockTab, ['tab_orders', 'tab_amounts', 'totals'])) {
$output = $this->layoutFactory->create()->createBlock('Magento\\Backend\\Block\\Dashboard\\' . $blockClassSuffix)->toHtml();
}
/** @var \Magento\Framework\Controller\Result\Raw $resultRaw */
$resultRaw = $this->resultRawFactory->create();
return $resultRaw->setContents($output);
}
示例14: execute
/**
* Get available attribute sets
*
* @return \Magento\Framework\Controller\Result\Raw
* @throws \Exception
*/
public function execute()
{
try {
/** @var \Magento\Framework\Controller\Result\Raw $resultRaw */
$resultRaw = $this->resultFactory->create(\Magento\Framework\Controller\ResultFactory::TYPE_RAW);
return $resultRaw->setContents($this->layoutFactory->create()->getBlockSingleton('Magento\\GoogleShopping\\Block\\Adminhtml\\Types\\Edit\\Form')->getAttributeSetsSelectElement($this->getRequest()->getParam('target_country'))->toHtml());
} catch (\Exception $e) {
$this->_objectManager->get('Psr\\Log\\LoggerInterface')->critical($e);
// just need to output text with error
$this->messageManager->addError(__("We can't load attribute sets."));
}
}
示例15: execute
/**
* Grid Action
* Display list of products related to current category
*
* @return \Magento\Framework\Controller\Result\Raw
*/
public function execute()
{
$category = $this->_initCategory(true);
if (!$category) {
/** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
$resultRedirect = $this->resultRedirectFactory->create();
return $resultRedirect->setPath('catalog/*/', ['_current' => true, 'id' => null]);
}
/** @var \Magento\Framework\Controller\Result\Raw $resultRaw */
$resultRaw = $this->resultRawFactory->create();
return $resultRaw->setContents($this->layoutFactory->create()->createBlock('Magento\\Catalog\\Block\\Adminhtml\\Category\\Tab\\Product', 'category.product.grid')->toHtml());
}