Custom Tailor field with many to many relation to regular model

Hi, in this previous question (Use Rainlab.Blog category in my tailor blueprint) I wondered how to link a rainlab category to my tailor blueprint. However, my need has evolved to a many to many relation (my tailor blueprint entries need to have many categories). So I guess my best bet is to build a custom field. It was a little bit hard for me to find something equivalent in the docs or in the forum. Could someone point me something that would help me for this ? Thanks!

Hi @hms

The documentation covers this here:

1 Like

Thanks for your answer! One thing that is for example not covered by the doc in my case is, how do I provide a list of elements for the backend form field? Iā€™m stuck at the moment with the error saying that there is no getCategoryOptions method for the category field. Any help appreciated on this! Thanks!

Actually found this one. In the field definition, the form field options are defined using options() method.

public function defineFormField(FormElement $form, $context = null)
    {
        $form->addFormField($this->fieldName, $this->label)->useConfig($this->config)->displayAs('dropdown')->options(
            //options array goes here
        );
    }