How to use relation button from another plugin?

Hello,

I have a relation config as below

blocks:
    label: Blocks
    deferredBinding: false
    showCheckboxes: false
    structure:
        showTree: false
        showReorder: true
        showSorting: true
    view:
        list: $/xyz/blocks/models/block/columns.yaml
        toolbarButtons: create|delete|copyBlock
    manage:
        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) {
            $this->handleError($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);
        $widget->bindToController();

        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>
    </div>

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

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

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

    <?php else: ?>

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

    <?php endif ?>

    <script>
        setTimeout(
            function(){ $('#extrasManageForm input.form-control:first').focus() },
            310
        )
    </script>

<?= Form::close() ?>