Magento 2;无法将自定义参数传递到 UI 窗体的保存按钮

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

我想通过我的用户界面管理表单的保存按钮传递一个值/参数。

我试过这个:

public function getButtonData()
    {
        $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
        $request = $objectManager->get('Magento\Framework\App\RequestInterface');
        $id = $request->getParam('id');

        return
            [
                'label' => __('Save'),
                'class' => 'save primary',
                'on_click' => '',
                'sort_order' => 80,
                'data_attribute' => [
                    'mage-init' => [
                        'Magento_Ui/js/form/button-adapter' => [
                            'actions' => [
                                [
                                    'targetName' => 'thechateau_magenest_bookable_save',
                                    'actionName' => 'save',
                                    'params' => [
                                        true,
                                        ['multidome_id' =>$id],
                                    ]
                                ]
                            ]
                        ]
                    ],

                ]
            ];
    }

我确实可以在 phtml 页面的保存按钮中看到值。

<button id="save" title="Save" type="button" class="action- scalable save primary" data-mage-init="{&quot;Magento_Ui\/js\/form\/button-adapter&quot;:{&quot;actions&quot;:[{&quot;targetName&quot;:&quot;thechateau_magenest_bookable_save&quot;,&quot;actionName&quot;:&quot;save&quot;,&quot;params&quot;:[true,{&quot;multidome_id&quot;:&quot;1&quot;}]}]}}"  data-ui-id="save-button" >
    <span>Save</span>
</button>

然而,当我尝试检索这些值时,它会出现空值。

$request = $this->_objectManager->create('Magento\Framework\App\RequestInterface');


$multiDome = $request->getParam('multidome_id');

我也尝试将它添加为保存按钮的 URL 的一部分,但它甚至没有出现在这个:

public function getSaveUrl()
    {
        return $this->getUrl('*/*/save',['param'=>'value']);

    }
magento2 uicomponents
1个回答
0
投票

您可以将任何参数添加到提交 URL。在您的控制器中处理某些情况可能很有用。 有“保存”按钮的例子。

public function getButtonData()
{
    return
        [
            'label' => __('Save'),
            'class' => 'save primary',
            'on_click' => '',
            'sort_order' => 10,
            'data_attribute' => [
                'mage-init' => [
                    'Magento_Ui/js/form/button-adapter' => [
                        'actions' => [
                            [
                                'targetName' => 'your_custom_form_or_listing_name.your_custom_form_or_listing_name',
                                'actionName' => 'save',
                                'params' => [
                                    true,
                                    ['custom_param' => 'qwerty123456'],
                                ]
                            ]
                        ]
                    ]
                ],

            ]
        ];
}

您也可以更改“保存并继续编辑”按钮。只是不要忘记添加到“params”参数“back”。 有“保存并继续编辑”按钮的示例。

public function getButtonData()
{
    return
        [
            'label' => __('Save and Continue Edit'),
            'class' => 'save',
            'on_click' => '',
            'sort_order' => 20,
            'data_attribute' => [
                'mage-init' => [
                    'Magento_Ui/js/form/button-adapter' => [
                        'actions' => [
                            [
                                'targetName' => 'your_custom_form_or_listing_name.your_custom_form_or_listing_name',
                                'actionName' => 'save',
                                'params' => [
                                    true,
                                    [
                                        'back' => 1,
                                        'custom_param' => 'qwerty123456',
                                    ]
                                ]
                            ]
                        ]
                    ]
                ],

            ]
        ];
}
© www.soinside.com 2019 - 2024. All rights reserved.