October CMS resources and help articles

Simple and to the point. Optimized by the community.

Add a custom button to a relation manager

by alxy, last modified on August 12th, 2019

Sometimes you may want to add a custom button to a relation widget to execute a custom action or extend the function of the default buttons. You can easily do this by specifying a custom key in the toolbarButtons option of your config_relation.yaml:

# ===================================
#  Relation Behavior Config
# ===================================

    label: Invoice Line Item
        list: $/acme/pay/models/invoiceitem/columns.yaml
        toolbarButtons: create|delete|custom # Add this
        form: $/acme/pay/models/invoiceitem/fields.yaml
        recordsPerPage: 10

Next, create a new file _relation_button_custom.htm (the last part corresponds to the item in your configuration file) in your controller's partial directory (e. g. /plugins/acme/controllers/invoices/) with the following contents:

        class="btn btn-sm btn-secondary"

In this case, the button will just call the handler onDoSomething of your controller. But you can also go more advanced and pass the selected (checked) items or any custom variables to the controller. You can even open a custom modal and render complex controls. A lot of the markup can be reused from the existing button partials.


1 comment

Post on August 2nd, 2020 8:55 PM

Thanks for this trick, it's possible to extends that form a plugin and load the views (of the button) from another plugin ? Thanks

We use cookies to measure the performance of this website. Do you want to accept these cookies?