This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

lucas.sanner54070
lucas.sanner54070

I need to slighly modify the checkboxes in the categories tab of my item. The original checkbox list partial lives here:
modules/backend/widgets/form/partials/_field_checkboxlist.htm
so I copied it into my plugin directory:
plugins/companyname/pluginname/models/item/_field_checkboxlist.htm
Now in my item field.yaml I added the path to the partial to extend.

     categories:
         type: relation
         path: ~/plugins/companyname/pluginname/models/item/_field_checkboxlist.htm

but the path is not taken into account. Conversely, if I change the field type

     categories:
         type: partial
         path: ~/plugins/companyname/pluginname/models/item/_field_checkboxlist.htm

the path is now taken into account but the category data is no longer available.

Is there a (easy) way to extend this partial without rewriting everything ?

mjauvin
mjauvin

Just add this to your controller:

    public function formExtendFieldsBefore($widget)
    {           
        $widget->addViewPath([ '$/companyname/pluginname/models/item' ]);
    }

Last updated

lucas.sanner54070
lucas.sanner54070

Nope, it doesn't work.
However I found out in which file the path should be modified:

modules/backend/formwidgets/relation/partials/_partial.htm

<div class="relation-widget" id="<?= $this->getId() ?>">
    <?= $this->makePartial('~/modules/backend/widgets/form/partials/_field_'.$field->type.'.htm', ['field' => $field]) ?>
</div>  

Of course I cannot hardcode a native file.
So would you have any idea about how to extend this file ?

mjauvin
mjauvin

It works fine, I tried it.

which field type are you trying to customize? Care to show the actual code you used in your controller?

mjauvin
mjauvin

If you're trying to modify the Relation formwidget, this is totally different. Use this in your plugin's boot method:

        \Backend\FormWidgets\Relation::extend(function ($widget) {
            $widget->addViewPath([ '$/companyname/pluginname/models/item' ]);
        });

And copy the file modules/backend/formwidgets/relation/partials/_relation.htm to your companyname/pluginname/models/item folder and adapt to your needs

Last updated

lucas.sanner54070
lucas.sanner54070

which field type are you trying to customize?
A relation type field.

The field data is computed through the makeRenderFormField() method in this file:
modules/backend/formwidgets/Relation.php
then rendered in this file:
modules/backend/formwidgets/relation/partials/_partial.htm

mjauvin
mjauvin

It's actually rendered in modules/backend/formwidgets/relation/partials/_relation.htm

Please see my previous post above, that should solve your problem

lucas.sanner54070
lucas.sanner54070

Awesome, it works !! Thanks !

1-8 of 8

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.