How to use relation button from another plugin?


I have a relation config as below

    label: Blocks
    deferredBinding: false
    showCheckboxes: false
        showTree: false
        showReorder: true
        showSorting: true
        list: $/xyz/blocks/models/block/columns.yaml
        toolbarButtons: create|delete|copyBlock
        form: $/xyz/blocks/models/block/fields.yaml
        recordsPerPage: 20

This is extended by another plugin as follows

$controller->addDynamicProperty('relationConfig', '$/xyz/blocks/controllers/blocks/config_relation.yaml');

The problem is that the copyBlock button is in the original plugin and not in the extended one.

i am wondering how can i use a relationButton from another plugin. for example:

toolbarButtons: create|delete|Xyz::Blocks.....copyBlock

Your best bet is to extend the controller with a custom handler and render a custom form. It will save a bunch of headaches in trying to set it up with a relation controller (which targets the common use case). Here’s a example

     * onLoadRestoreExtrasSetForm
    public function onLoadRestoreExtrasSetForm()
        try {
            $this->vars['formWidget'] = $this->getExtraSetFormWidget();
        catch (Exception $ex) {

        return $this->makePartial('extraset_manage_form');

     * getExtraSetFormWidget
    protected function getExtraSetFormWidget()
        $fields = '$/responsiv/shop/models/productextraset/fields-load.yaml';

        $config = $this->makeConfig($fields);
        $config->arrayName = 'ProductExtraSet';
        $config->model = new ProductExtraSet;
        $widget = $this->makeWidget(\Backend\Widgets\Form::class, $config);

        return $widget;

And the form

<?= Form::open(['id' => 'extrasManageForm']) ?>

    <div class="modal-header">
        <h4 class="modal-title"><?= __("Load Extra Option Set") ?></h4>
        <button type="button" class="btn-close" data-dismiss="popup"></button>

    <?php if (!$this->fatalError): ?>

        <div class="modal-body">
            <?= $formWidget->render() ?>
        <div class="modal-footer">
            <?= Ui::ajaxButton("Load", 'onRestoreExtraSet')
                ->primary() ?>

            <?= Ui::button(__("Cancel"))->dismissPopup() ?>

    <?php else: ?>

        <div class="modal-body">
            <p class="flash-message static error"><?= e(trans($this->fatalError)) ?></p>
        <div class="modal-footer">
            <?= Ui::button(__("Close"))->dismissPopup() ?>

    <?php endif ?>

            function(){ $('#extrasManageForm input.form-control:first').focus() },

<?= Form::close() ?>