本文整理汇总了PHP中Magento\Framework\View\LayoutInterface::createBlock方法的典型用法代码示例。如果您正苦于以下问题:PHP LayoutInterface::createBlock方法的具体用法?PHP LayoutInterface::createBlock怎么用?PHP LayoutInterface::createBlock使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Framework\View\LayoutInterface
的用法示例。
在下文中一共展示了LayoutInterface::createBlock方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getAfterElementHtml
/**
* Retrieve additional html and put it at the end of element html
*
* @return string
*/
public function getAfterElementHtml()
{
$html = parent::getAfterElementHtml();
if ($this->getIsWysiwygEnabled()) {
$disabled = $this->getDisabled() || $this->getReadonly();
$html .= $this->_layout->createBlock('Magento\\Backend\\Block\\Widget\\Button', '', array('data' => array('label' => __('WYSIWYG Editor'), 'type' => 'button', 'disabled' => $disabled, 'class' => $disabled ? 'disabled action-wysiwyg' : 'action-wysiwyg', 'onclick' => 'catalogWysiwygEditor.open(\'' . $this->_backendData->getUrl('catalog/product/wysiwyg') . '\', \'' . $this->getHtmlId() . '\')')))->toHtml();
$html .= <<<HTML
<script type="text/javascript">
jQuery('#{$this->getHtmlId()}')
.addClass('wysiwyg-editor')
.data(
'wysiwygEditor',
new tinyMceWysiwygSetup(
'{$this->getHtmlId()}',
{
settings: {
theme_advanced_buttons1 : 'bold,italic,|,justifyleft,justifycenter,justifyright,|,' +
'fontselect,fontsizeselect,|,forecolor,backcolor,|,link,unlink,image,|,bullist,numlist,|,code',
theme_advanced_buttons2: null,
theme_advanced_buttons3: null,
theme_advanced_buttons4: null,
theme_advanced_statusbar_location: null
}
}
).turnOn()
);
</script>
HTML;
}
return $html;
}
示例2: setUp
protected function setUp()
{
parent::setUp();
$this->_layout = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('Magento\\Framework\\View\\LayoutInterface');
$this->_theme = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Framework\\View\\Design\\ThemeInterface');
$this->_theme->setType(\Magento\Framework\View\Design\ThemeInterface::TYPE_VIRTUAL);
$this->_block = $this->_layout->createBlock('Magento\\Theme\\Block\\Adminhtml\\System\\Design\\Theme\\Edit\\Tab\\General');
}
示例3: execute
/**
* Adds Google Experiment tab to the category edit page
*
* @param EventObserver $observer
* @return void
*/
public function execute(EventObserver $observer)
{
if ($this->_helper->isGoogleExperimentActive()) {
$block = $this->_layout->createBlock('Magento\\GoogleOptimizer\\Block\\Adminhtml\\Catalog\\Category\\Edit\\Tab\\Googleoptimizer', 'google-experiment-form');
/** @var $tabs \Magento\Catalog\Block\Adminhtml\Category\Tabs */
$tabs = $observer->getEvent()->getTabs();
$tabs->addTab('google-experiment-tab', ['label' => __('Category View Optimization'), 'content' => $block->toHtml()]);
}
}
示例4: setUp
protected function setUp()
{
$this->_payment = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\RecurringPayment\\Model\\Payment');
/** @var $objectManager \Magento\TestFramework\ObjectManager */
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
$objectManager->get('Magento\\Framework\\Registry')->register('current_recurring_payment', $this->_payment);
$this->_layout = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('Magento\\Framework\\View\\LayoutInterface');
$this->_block = $this->_layout->createBlock('Magento\\RecurringPayment\\Block\\Payment\\View', 'block');
}
示例5: aroundRender
/**
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
* @param \Magento\LayeredNavigation\Block\Navigation\FilterRenderer $subject
* @param \Closure $proceed
* @param \Magento\Catalog\Model\Layer\Filter\FilterInterface $filter
* @return mixed
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function aroundRender(\Magento\LayeredNavigation\Block\Navigation\FilterRenderer $subject, \Closure $proceed, \Magento\Catalog\Model\Layer\Filter\FilterInterface $filter)
{
if ($filter->hasAttributeModel()) {
if ($this->swatchHelper->isSwatchAttribute($filter->getAttributeModel())) {
return $this->layout->createBlock($this->block)->setSwatchFilter($filter)->toHtml();
}
}
return $proceed($filter);
}
示例6: create
/**
* Get renderer for element
*
* @param string $elementClassName
* @param string $rendererName
* @return RendererInterface
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function create($elementClassName, $rendererName)
{
if (!isset($this->_rendererByElement[$elementClassName])) {
throw new \Magento\Framework\Exception\LocalizedException(__('No renderer registered for elements of class "%1"', $elementClassName));
}
$rendererClass = $this->_rendererByElement[$elementClassName];
$renderer = $this->_layout->createBlock($rendererClass, $rendererName);
return $renderer;
}
示例7: setUp
protected function setUp()
{
parent::setUp();
$this->_layoutMock = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('Magento\\Framework\\View\\LayoutInterface');
$context = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Backend\\Block\\Template\\Context', ['layout' => $this->_layoutMock]);
$this->_block = $this->_layoutMock->createBlock('Magento\\Backend\\Block\\Widget\\Grid\\Extended', 'grid', ['context' => $context]);
$this->_block->addColumn('column1', ['id' => 'columnId1']);
$this->_block->addColumn('column2', ['id' => 'columnId2']);
}
示例8: getContentHtml
/**
* Prepares content block
*
* @return string
*/
public function getContentHtml()
{
/* @var $content \Magento\Catalog\Block\Adminhtml\Product\Helper\Form\Gallery\Content */
$content = $this->_layout->createBlock('Magento\\Catalog\\Block\\Adminhtml\\Product\\Helper\\Form\\Gallery\\Content');
$content->setId($this->getHtmlId() . '_content')->setElement($this);
$galleryJs = $content->getJsObjectName();
$content->getUploader()->getConfig()->setMegiaGallery($galleryJs);
return $content->toHtml();
}
示例9: testAfterToHtml
/**
* @covers \Magento\Sales\Block\Adminhtml\Report\Filter\Form\Coupon::_afterToHtml
*/
public function testAfterToHtml()
{
/** @var $block \Magento\Sales\Block\Adminhtml\Report\Filter\Form\Coupon */
$block = $this->_layout->createBlock('Magento\\Sales\\Block\\Adminhtml\\Report\\Filter\\Form\\Coupon');
$block->setFilterData(new \Magento\Framework\DataObject());
$html = $block->toHtml();
$expectedStrings = ['FormElementDependenceController', 'sales_report_rules_list', 'sales_report_price_rule_type'];
foreach ($expectedStrings as $expectedString) {
$this->assertContains($expectedString, $html);
}
}
示例10: testDeleteButtonExistInCustomGroup
/**
* @magentoDataFixture Magento/Customer/_files/customer_group.php
*/
public function testDeleteButtonExistInCustomGroup()
{
$builder = Bootstrap::getObjectManager()->create('Magento\\Framework\\Api\\FilterBuilder');
/** @var \Magento\Framework\Api\SearchCriteriaBuilder $searchCriteria */
$searchCriteria = Bootstrap::getObjectManager()->create('Magento\\Framework\\Api\\SearchCriteriaBuilder')->addFilters([$builder->setField('code')->setValue('custom_group')->create()])->create();
$customerGroup = $this->groupRepository->getList($searchCriteria)->getItems()[0];
$this->getRequest()->setParam('id', $customerGroup->getId());
$this->registry->register(RegistryConstants::CURRENT_GROUP_ID, $customerGroup->getId());
/** @var $block Edit */
$block = $this->layout->createBlock('Magento\\Customer\\Block\\Adminhtml\\Group\\Edit', 'block');
$buttonsHtml = $block->getButtonsHtml();
$this->assertContains('delete', $buttonsHtml);
}
示例11: setWeeeRendererInForm
/**
* Assign custom renderer for product create/edit form weee attribute element
*
* @param \Magento\Framework\Event\Observer $observer
* @return $this
*/
public function setWeeeRendererInForm(\Magento\Framework\Event\Observer $observer)
{
/** @var \Magento\Framework\Data\Form $form */
$form = $observer->getEvent()->getForm();
$attributes = $this->_weeeTax->getWeeeAttributeCodes(true);
foreach ($attributes as $code) {
$weeeTax = $form->getElement($code);
if ($weeeTax) {
$weeeTax->setRenderer($this->_layout->createBlock('Magento\\Weee\\Block\\Renderer\\Weee\\Tax'));
}
}
return $this;
}
示例12: getAfterElementHtml
/**
* Retrieve additional html and put it at the end of element html
*
* @return string
*/
public function getAfterElementHtml()
{
$config = $this->_wysiwygConfig->getConfig();
$config = json_encode($config->getData());
$html = parent::getAfterElementHtml();
if ($this->getIsWysiwygEnabled()) {
$disabled = $this->getDisabled() || $this->getReadonly();
$html .= $this->_layout->createBlock('Magento\\Backend\\Block\\Widget\\Button', '', ['data' => ['label' => __('WYSIWYG Editor'), 'type' => 'button', 'disabled' => $disabled, 'class' => 'action-wysiwyg', 'onclick' => 'catalogWysiwygEditor.open(\'' . $this->_backendData->getUrl('catalog/product/wysiwyg') . '\', \'' . $this->getHtmlId() . '\')']])->toHtml();
$html .= <<<HTML
<script>
require([
'jquery',
'mage/adminhtml/wysiwyg/tiny_mce/setup'
], function(jQuery){
var config = {$config},
editor;
jQuery.extend(config, {
settings: {
theme_advanced_buttons1 : 'bold,italic,|,justifyleft,justifycenter,justifyright,|,' +
'fontselect,fontsizeselect,|,forecolor,backcolor,|,link,unlink,image,|,bullist,numlist,|,code',
theme_advanced_buttons2: null,
theme_advanced_buttons3: null,
theme_advanced_buttons4: null,
theme_advanced_statusbar_location: null
},
files_browser_window_url: false
});
editor = new tinyMceWysiwygSetup(
'{$this->getHtmlId()}',
config
);
editor.turnOn();
jQuery('#{$this->getHtmlId()}')
.addClass('wysiwyg-editor')
.data(
'wysiwygEditor',
editor
);
});
</script>
HTML;
}
return $html;
}
示例13: createElementHtmlOutputBlock
/**
* @return \Magento\Framework\View\Element\Template
*/
public function createElementHtmlOutputBlock()
{
/** @var \Magento\Framework\View\Element\Template $block */
$block = $this->layout->createBlock('Magento\\Framework\\View\\Element\\Template', 'product.details.form.base.image.element');
$block->setTemplate(self::ELEMENT_OUTPUT_TEMPLATE);
return $block;
}
示例14: blockDirective
/**
* Retrieve Block html directive
*
* @param array $construction
* @return string
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
public function blockDirective($construction)
{
$skipParams = ['class', 'id', 'output'];
$blockParameters = $this->_getIncludeParameters($construction[2]);
$block = null;
if (isset($blockParameters['class'])) {
$block = $this->_layout->createBlock($blockParameters['class'], null, ['data' => $blockParameters]);
} elseif (isset($blockParameters['id'])) {
$block = $this->_layout->createBlock('Magento\\Cms\\Block\\Block');
if ($block) {
$block->setBlockId($blockParameters['id']);
}
}
if (!$block) {
return '';
}
$block->setBlockParams($blockParameters);
foreach ($blockParameters as $k => $v) {
if (in_array($k, $skipParams)) {
continue;
}
$block->setDataUsingMethod($k, $v);
}
if (isset($blockParameters['output'])) {
$method = $blockParameters['output'];
}
if (!isset($method) || !is_string($method) || !method_exists($block, $method) || !is_callable([$block, $method])) {
$method = 'toHtml';
}
return $block->{$method}();
}
示例15: testGetFormExistInCustomGroup
/**
* @magentoDataFixture Magento/Customer/_files/customer_group.php
*/
public function testGetFormExistInCustomGroup()
{
$builder = Bootstrap::getObjectManager()->create('Magento\\Framework\\Service\\V1\\Data\\FilterBuilder');
/** @var \Magento\Framework\Service\V1\Data\SearchCriteriaBuilder $searchCriteria */
$searchCriteria = Bootstrap::getObjectManager()->create('Magento\\Framework\\Service\\V1\\Data\\SearchCriteriaBuilder')->addFilter([$builder->setField('code')->setValue('custom_group')->create()])->create();
/** @var CustomerGroup $customerGroup */
$customerGroup = $this->customerGroupService->searchGroups($searchCriteria)->getItems()[0];
$this->registry->register(RegistryConstants::CURRENT_GROUP_ID, $customerGroup->getId());
/** @var $block Form */
$block = $this->layout->createBlock('Magento\\Customer\\Block\\Adminhtml\\Group\\Edit\\Form', 'block');
$form = $block->getForm();
$this->assertEquals('edit_form', $form->getId());
$this->assertEquals('post', $form->getMethod());
$baseFieldSet = $form->getElement('base_fieldset');
$this->assertNotNull($baseFieldSet);
$groupCodeElement = $form->getElement('customer_group_code');
$this->assertNotNull($groupCodeElement);
$taxClassIdElement = $form->getElement('tax_class_id');
$this->assertNotNull($taxClassIdElement);
$idElement = $form->getElement('id');
$this->assertNotNull($idElement);
$this->assertEquals($customerGroup->getId(), $idElement->getValue());
$this->assertEquals($customerGroup->getTaxClassId(), $taxClassIdElement->getValue());
/** @var \Magento\Tax\Model\TaxClass\Source\Customer $taxClassCustomer */
$taxClassCustomer = Bootstrap::getObjectManager()->get('Magento\\Tax\\Model\\TaxClass\\Source\\Customer');
$this->assertEquals($taxClassCustomer->toOptionArray(false), $taxClassIdElement->getData('values'));
$this->assertEquals($customerGroup->getCode(), $groupCodeElement->getValue());
}