Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

However, to add allowance for the new button, in this case reset_former_plugin_settings, the button should be added in the $allowedFormData-array and the columns-array, like in this example. The columns array is only necessary if you plan to change the layout format to "columnable"  buttons like this:

Image Added

This is how it looks:

Code Block
languagephp
    public function getFieldButtonApi($formData)
    {
        $action = isset($formData['action']) && !empty($formData['action']) ? $formData['action'] : 'button';

        $allowedFormData = [
            Data::getPrefix('admin_payment_methods_button'),
            Data::getPrefix('admin_callbacks_button'),
            Data::getPrefix('admin_trigger_callback_button'),
            Data::getPrefix('admin_the_reset_button'),
            Data::getPrefix('admin_reset_former_plugin_settings'),
        ];

        if (isset($formData['id']) && in_array($formData['id'], $allowedFormData, true)) {
            $formArray = $formData;
            $formArray['action'] = $action; // Our action
            $formArray['custom_attributes'] = $this->get_custom_attribute_html($formData);
            $formArray['columns'] = [
                'the_reset_button' => true,
                'reset_former_plugin_settings' => true
            ];
            $formArray['short_id'] = preg_replace(sprintf('/%s_admin_/', Data::getPrefix()), '', $formArray['id']);
            echo Data::getEscapedHtml(
                Data::getGenericClass()->getTemplate('adminpage_button', $formArray)
            );
        }
    }

...