我正在尝试使用自定义管理表单中的Ui界面动态添加一些fiels。
在order_ticket_form.xml
中
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
---
<fieldset name="message" class="Bileamara\SalesOrderGrid\Ui\Component\Form\Fieldset\Ticket\Message">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="label" xsi:type="string" translate="true">Add Message in Every Language</item>
<item name="sortOrder" xsi:type="number">20</item>
</item>
</argument>
</fieldset>
</form>
和Bileamara \ SalesOrderGrid \ Ui \ Component \ Form \ Fieldset \ Ticket \ Message
<?php
namespace Bileamara\SalesOrderGrid\Ui\Component\Form\Fieldset\Ticket;
use Magento\Framework\View\Element\UiComponent\ContextInterface;
use Magento\Framework\View\Element\UiComponentInterface;
use Magento\Ui\Component\Form\FieldFactory;
use Magento\Ui\Component\Form\Fieldset as BaseFieldset;
use Magento\Store\Model\System\Store as SystemStore;
use Magento\Cms\Model\Wysiwyg\Config as WysiwygConfig;
class Message extends BaseFieldset
{
/**
* @var FieldFactory
*/
private $fieldFactory;
protected $systemStore;
public function __construct(
WysiwygConfig $wysiwygConfig,
SystemStore $systemStore,
ContextInterface $context,
array $components = [],
array $data = [],
FieldFactory $fieldFactory)
{
parent::__construct($context, $components, $data);
$this->_wysiwygConfig = $wysiwygConfig;
$this->systemStore = $systemStore;
$this->fieldFactory = $fieldFactory;
}
/**
* Get components
*
* @return UiComponentInterface[]
*/
public function getChildComponents()
{
$wysiwygConfig = $this->_wysiwygConfig->getConfig([
'hidden' => 0
]);
$storeCollection = $this->systemStore->getStoreCollection();
foreach ($storeCollection as $store) {
$fields['message_'.$store->getCode()] = [
'formElement' => 'wysiwyg',
'label' => $store->getName(),
'wysiwyg' => true,
'required' => true,
'config' => $wysiwygConfig,
];
}
foreach ($fields as $name => $fieldConfig) {
$fieldInstance = $this->fieldFactory->create();
$fieldInstance->setData(
[
'config' => $fieldConfig,
'name' => $name,
]
);
$fieldInstance->prepare();
$this->addComponent($name, $fieldInstance);
}
return parent::getChildComponents();
}
}
现在我得到了田地
但:
- editor is hidden and should be visible
- label is missing
- there is no space betwin fields
我需要设置与名称不同的字段ID,像
一样- id =>message_en
- name =>message[en]
因为我需要在数组中生成消息。
任何帮助?
最新回答
- 2019-12-51 #
我需要添加
'template' => 'ui/form/field'
在现场配置中所以现在代码是仍然想知道是否有机会按照订单形式对地址字段等字段进行分组,例如message [en]