octobercms / october

Self-hosted CMS platform based on the Laravel PHP Framework.
https://octobercms.com/
Other
10.99k stars 2.22k forks source link

Call to undefined method Backend\Widgets\Lists::setFormValues #5793

Closed wpluut closed 3 months ago

wpluut commented 3 months ago

I have a model with a morphMany realtionship, called 'dates':

public $morphMany = [
    'dates' => [
        Date::class,
        'name'  => 'dateable',
        'order' => 'start'
    ]
];

In my fields.yaml file I render these 'dates' with a partial, like:

        dates:
            type: partial
            tab: Data
            context: update

The partial only renders the relation (so nothing fancy):

<?= $this->relationRender('dates') ?>

This worked in OctoberCMS 3.5.x but the latest OctoberCMS version 3.6.11 gives the following error:

Call to undefined method Backend\Widgets\Lists::setFormValues

For now I have downgraded to the 3.5.x version. Do you have any ideas on what is wrong?

daftspunk commented 3 months ago

Hi @wpluut

In v3.6, the relation controller will initialize all the necessary widgets, even if they are not used. In v3.5, it would try to guess whether they were used or not. This change was necessary to allow nested relations to function correctly.

The error can occur when an event previously provided a Form widget now gets a List widget. This can happen in the relationExtendManageWidget or relationExtendViewWidget method overrides in your controller.

There are two options:

Old Method New Method
relationExtendViewWidget relationExtendViewFormWidget
relationExtendManageWidget relationExtendManageFormWidget

I hope this helps.

wpluut commented 3 months ago

Hi @daftspunk,

Thanks! Overriding relationExtendManageWidget to relationExtendManageFormWidget solved the issue.