Open sebastianbaumann opened 6 years ago
Probably specific to it being inside a list. Can you test/confirm if it saves correctly outside the list?
title: Seite
'@extends':
type: default
context: blueprints://pages
form:
fields:
tabs:
type: tabs
active: 1
fields:
content:
unset@: true
type: tab
title: Seite
fields:
header.headline:
type: text
label: Seitenüberschrift
# not working
header.test:
type: taxonomy
label: PLUGIN_ADMIN.TAXONOMY
multiple: true
validate:
type: array
# working
header.taxonomy:
type: taxonomy
label: PLUGIN_ADMIN.TAXONOMY
multiple: true
validate:
Sure! Works outside a list, when the field is named taxonomy
otherwise it doesn't.
Any news…?
Outside of a list, I can confirm this bug. When trying to use the taxonomy
field type, unless it's named header.taxonomy
it will not populate. It does save if it has a different name, though.
My blueprint
header.taxes:
type: taxonomy
label: PLUGIN_ADMIN.TAXONOMY
multiple: true
style: vertical
validate:
type: array
It creates and saves the fields correctly for the page frontmatter.
taxes:
category:
- staff
tag:
- corporate
It doesn't populate the field from the admin page, though. It even has the correct name for the select on the admin page name="data[header][taxes][category][]"
, but it won't actually populate the field.
Naming the header field taxonomy
will populate the field, though.
@rhukster If I understand this correctly, it appears that the taxonomy
field is hardcoded to pull its data from header.taxonomy
instead of using data that matches the blueprint's field name.
See this line of code: https://github.com/getgrav/grav-plugin-admin/blob/develop/themes/grav/templates/forms/fields/taxonomy/taxonomy.html.twig#L11
I have also encountered this issue. As a hacky workaround, I created a static function in my plugin that will return some "default" data. e.g. on my taxonomy field I add:
header.example:
type: taxonomy
label: PLUGIN_ADMIN.TAXONOMY
# DEFINE YOUR OWN STATIC PHP FUNCTION AS DEFAULT
default@: '\Grav\Plugin\MyPlugin::getDefaultTaxonomyData'
multiple: true
validate:
type: array
In this function, I have to figure out the form page's context (i.e. which page you are editing. I did this by using the Uri
class and parsing the url -- not super reliable) and then fetching the correct data manually in my function and returning this array. The taxonomy field will then populate the form correctly with the custom "default" data.
It would be much nicer if the taxonomy.html.twig
template could be updated to allow different data sources, however!
I agree it probably needs an update to allow more dynamic ways of setting the taxonomy
P.S. @Regaez there's easier ways to figure out what page you are editing - you can message me on discord if you want to know more
I created a custom
page.collection
for a listing page containing some products. After that, I created the respective blueprint file. Everything is perfectly fine, until I try to edit and save the taxonomy categories from the admin panel.The markdown file is filled with the correct input, but after reloading the admin panel, the previously filled category field is empty.
This is my
productlist.md
This is my blueprint
productlist.yaml
As you can see, after saving from the admin panel, the markdown file is filled correctly. But the admin panel stays empty.