This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.
Hi guys!
I'm extending the static pages plugin to include a custom tab, this works great:
Page::extend(function ($model) {
$model->addDynamicMethod('getCountryOptions', function () {
return ['au', 'ca', 'rr'];
});
});
// Extend all backend form usage
Event::listen('backend.form.extendFields', function ($widget) {
// Only for the Pages controller
if (!$widget->getController() instanceof \RainLab\Pages\Controllers\Index) {
return;
}
$widget->addTabFields([
'country' => [
'label' => 'Country',
'tab' => 'Additional',
'type' => 'dropdown'
]
]);
});
Since no options are given, the values for the dropdown are fetched (as documented) from the getFieldOptions() method, in this case the getCountryOptions() method, since the field is named "country" - works great.
However, now it gets tricky. In order to have this new TabField stored in the viewbag, I actually need to write:
$widget->addTabFields([
'viewBag[country]' => [
'label' => 'Country',
'tab' => 'Additional',
'type' => 'dropdown'
]
]);
The problem now is, that my getCountryOptions() method is no longer working, in fact I'm getting an error: "get_class() expects parameter 1 to be object, array given" on line 1039 ..."
It obviously tries to interpret the viewBag[country] as a method name in order to find the corresponding method for filling the dropdown with values.
Can anyone please give me some input here, how I can get this to work together?
Many thanks and all the best, Michael
Last updated
Hi all,
I resolved this by providing the filler method directly through the "options" field:
'viewBag[country]' => [
'label' => 'Country',
'tab' => 'Addl',
'type' => 'dropdown',
'options' => 'getCountryOptions'
],
All the best, Michael
1-2 of 2