保存按钮不适用于自定义模块形式

问题描述 投票:1回答:1

[使用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);
    }
}

提前感谢

magento magento2
1个回答
0
投票
这里有同样的问题。

推荐问答