使用uicomponent在Magento Admin中创建了一个自定义模块编辑表单,但是当我单击“保存”按钮时,它会重定向到同一个编辑页面,而不是在创建保存按钮时指定的操作页面上。它会在关键参数之后使用URL中的未定义参数重定向到编辑页面。我错过了什么?以下是我用来生成按钮的代码。
<item name="buttons" xsi:type="array">
<item name="back" xsi:type="string"><Vendor>\<Module>\Block\Adminhtml\Listings\Edit\BackButton</item>
<item name="delete" xsi:type="string"><Vendor>\<Module>\Block\Adminhtml\Listings\Edit\DeleteButton</item>
<item name="save" xsi:type="string"><Vendor>\<Module>\Block\Adminhtml\Listings\Edit\SaveButton</item>
</item>
SaveButton.php
<?php
namespace <Vendor>\<Module>\Block\Adminhtml\Listings\Edit;
use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;
/**
* Class SaveButton
*/
class SaveButton extends GenericButton implements ButtonProviderInterface
{
/**
* @return array
*/
public function getButtonData()
{
$url = $this->getUrl('properties/listings/update', ['property_id' => $this->getId()]);
return [
'label' => __('Save Property'),
'class' => 'save primary',
'data_attribute' => [
'mage-init' => ['button' => ['event' => 'save']],
'form-role' => 'save',
],
'sort_order' => 90,
'action' => $url
];
}
}
GenericButton.php
<?php
namespace <Vendor>\<Module>\Block\Adminhtml\Listings\Edit;
use Magento\Search\Controller\RegistryConstants;
/**
* Class GenericButton
*/
class GenericButton
{
/**
* Url Builder
*
* @var \Magento\Framework\UrlInterface
*/
protected $urlBuilder;
/**
* Registry
*
* @var \Magento\Framework\Registry
*/
protected $registry;
/**
* Constructor
*
* @param \Magento\Backend\Block\Widget\Context $context
* @param \Magento\Framework\Registry $registry
*/
public function __construct(
\Magento\Backend\Block\Widget\Context $context,
\Magento\Framework\Registry $registry
) {
$this->urlBuilder = $context->getUrlBuilder();
$this->registry = $registry;
}
/**
* Return the synonyms group Id.
*
* @return int|null
*/
public function getId()
{
$data = $this->registry->registry('property_data');
//return $contact ? $contact->getId() : null;
return $data['property_id'];
}
/**
* Generate url by route and parameters
*
* @param string $route
* @param array $params
* @return string
*/
public function getUrl($route = '', $params = [])
{
return $this->urlBuilder->getUrl($route, $params);
}
}
提前致谢
答案 0 :(得分:0)
这里有同样的问题。
由于provider.js中的submit_url未定义
client = commands.Bot(command_prefix = 'somethingelse')
client.remove_command('help')
我在数据源中的js_config下使用了commit_url解决了
defaults: {
clientConfig: {
urls: {
save: '${ $.submit_url }',
beforeSave: '${ $.validate_url }'
}
}
},
来源:https://magento.stackexchange.com/questions/139639/uicomponent-form-save-button-not-working