This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.
Hello,
I receive the following error message, when I'm using the nestedform
field type on the configuration page of my template:
"Unexpected type of array when attempting to save attribute
_any attribute_
, try adding it to the $jsonable property." on line 721 of home\vendor\october\rain\src\Database\Model.php
I do understand this error, but I'm not quite sure why it occurs, since the ThemeData
Model should pass the additional _any attribute_
to the jsonable'd data
attribute too (I mean, this is also done on all non-nestedform types).
I already tried to use data[_any attribute_]
instead of _any attribute_
on the nestedform
fields, and at least the error is gone... but the data did not save. My second approach was using nonsense repeaters with _any attribute_
as key (to force an array or something) and it also "bypassed" the error message... but the data did still not save. My last idea was an adapted NestedForm.php
formwidget within my theme's folder (which removes / skips the "parent" key from the fieldName part), but the whole themes directory isn't included in the autoloader.
I checked the related LoC's, but I couldn't find any other solution or workaround, which can be done without coding using an additional plugin.
So... Is there any solution, which can be done without plugin / just within the themes configuration? Or am I missing something obvious?
Thanks!
~Sam.
Last updated
Just in case it's important:
My theme.yaml file looks like this:
name: _name_
code: _code_
description: _description_
author: Synder
author_code: Synder
homepage: _homepage_
parent: ''
database: '0'
form: config/customize.yaml
require:
- RainLab.Blog
- RainLab.Pages
- RainLab.Translate
translate:
en: ~/themes/reboot/lang/lang.yaml
de: ~/themes/reboot/lang/lang.yaml
My config/customize.yaml file looks like this (Everything with _non-nestform_
works fine):
enableDefaults: true
tabs:
stretch: true
defaultTab: theme.reboot::lang.customize.tabs.homepage
fields:
site_name:
_non-nestform_
site_description:
_non-nestform_
site_logo:
_non-nestform_
site_keywords:
_non-nestform_
_ruler1:
_non-nestform_
color_primary:
_non-nestform_
accent_color:
_non-nestform_
color_secondary:
_non-nestform_
link_color:
_non-nestform_
_ruler2:
_non-nestform_
social_links:
_non-nestform_
data[homepage]:
tab: theme.reboot::lang.customize.tabs.homepage
type: nestedform
form: ~/themes/reboot/config/_form_homepage.yaml
showPanel: false
data[single]:
tab: theme.reboot::lang.customize.tabs.single
type: nestedform
form: ~/themes/reboot/config/_form_single.yaml
showPanel: false
data[footer]:
tab: theme.reboot::lang.customize.tabs.footer
type: nestedform
form: ~/themes/reboot/config/_form_footer.yaml
showPanel: false
data[plugins]:
tab: theme.reboot::lang.customize.tabs.plugins
type: nestedform
form: ~/themes/reboot/config/_form_plugins.yaml
showPanel: false
custom_css:
_non-nestform_
The reason why I'm using nestedform
is to separate the numerous options for a better maintenance and overview in general, since I can only pass a new YAML file path on the form
key, I guess?
Hey Sam!
It looks like the nestedform
type is not recognised by the ThemeData model. You could try adding support for it by opening this file modules\cms\models\ThemeData.php and navigating to the afterFetch
method.
Change this line:
if ($field['type'] === 'repeater') {
To:
if (in_array($field['type'], ['repeater', 'nestedform'])) {
If this works, let us know and we can include it in the next release.
Hello,
thanks, this solution works great. The settings are now stored accordingly and can be accessed on the theme!
~Sam.
PS.: Just as a side-note, since it is not written down in the documentation, it is also possible to force the defaults with two small steps:
- You need to include
enableDefaults: true
on the primary / parent form (as shown in my code above), next totabs
orfields
depending on your configuration. - You need to pass the defaults as JSON-encoded string on the
nestedform
field type, such as:
footer:
tab: theme.reboot::lang.customize.tabs.footer
type: nestedform
form: ~/themes/reboot/config/_form_footer.yaml
default: '{"scroll_to_top": true, "copyright_line1": "Copyright © %now% - %site_name%.", "copyright_line2": "All rights reserved.", "reboot_notice": true, "october_notice": true}'
showPanel: false
The first step is required to show the defaults on the admin configuration page, the second step to "enable" or "use" the defaults on the frontend (if the user did not change / save the settings yet).
Last updated
1-5 of 5