I actualized Magento to version 2.1 and my buttons stopped working. I'm not sure what I've changed. Actual version of files below.
My problem is to send save request to proper action (before it were working by ajax.) to controller action. Now if it even redirect page. I can't get post data on it. (is empty array).
settings_form.xml
<argument name="data" xsi:type="array">
<item name="js_config" xsi:type="array">
<item name="provider" xsi:type="string">settings_form.correctemail_settings_form_data_source</item>
<item name="deps" xsi:type="string">settings_form.correctemail_settings_form_data_source</item>
</item>
<item name="label" xsi:type="string" translate="true">Sample Form</item>
<item name="layout" xsi:type="array">
<item name="type" xsi:type="string">tabs</item>
</item>
<item name="buttons" xsi:type="array">
<item name="save" xsi:type="string">iDesign\Correctemail\Block\Adminhtml\Buttons\Save</item>
<item name="update" xsi:type="array">
<item name="name" xsi:type="string">update</item>
<item name="label" xsi:type="string">Save Settings</item>
<item name="class" xsi:type="string">primary</item>
<item name="url" xsi:type="string">*/*/save</item>
</item>
</item>
</argument>
<dataSource name="correctemail_settings_form_data_source">
<argument name="dataProvider" xsi:type="configurableObject">
<argument name="class" xsi:type="string">iDesign\Correctemail\Model\Settings\DataProvider</argument>
<argument name="name" xsi:type="string">correctemail_settings_form_data_source</argument>
<argument name="primaryFieldName" xsi:type="string">settings_id</argument>
<argument name="requestFieldName" xsi:type="string">settings_id</argument>
<argument name="data" xsi:type="array">
<item name="js_config" xsi:type="array">
<item name="component" xsi:type="string">Magento_Ui/js/grid/provider</item>
</item>
<item name="config" xsi:type="array">
<item name="submit_url" xsi:type="url" path="*/*/*"/>
</item>
</argument>
</argument>
<argument name="data" xsi:type="array">
<item name="js_config" xsi:type="array">
<item name="component" xsi:type="string">Magento_Ui/js/form/provider</item>
</item>
</argument>
</dataSource>
<fieldset>
...
</fieldset>
Block/Adminhtml/Buttons/Save.php
use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;
class Save implements ButtonProviderInterface
{
public function getButtonData()
{
return [
'label' => 'Save',
'class' => 'save primary',
'data_attribute' => [
'mage-init' => [
'button' => ['event' => 'save'],
],
],
'sort_order' => 80,
];
}
}
GenericButton.php
class GenericButton
{
/**
* @var Context
*/
protected $context;
/**
* @param Context $context
*/
public function __construct(Context $context)
{
$this->context = $context;
}
/**
* Return Settings ID
*
* @return int
*/
public function getSettingsId()
{
return 1;
}
/**
* Generate url by route and parameters
*
* @param string $route
* @param array $params
* @return string
*/
public function getUrl($route = '', $params = [])
{
return $this->context->getUrlBuilder()->getUrl($route, $params);
}
}
When I Inspect button html I have inside
onclick="location.href=... myModuleName/index/index ... (why?)
Other thing is. Why after reload my url gets at the end /undefined string
mage.dev/index.php/admin/ModuleName/settings/index/settings_id/1/key/9a71fd4a4f84367a354a134e399addc67dd95868a29651b37f6a4083ecd0fc05/undefined