Hi!
after defining a RelatedItems field in dexterity TTW, if the object instance is inside a navigation root the widget is unable to work correctly. This is because when it is a field widget, RelatedItemsFieldWidget uses @@getSource to query the catalog and this view overwrite the path using plone.app.querystring.queryparser._navigationPath in a wrong way (basically it mess with the path) when the object is under a folder that is a navigation root. You can see it easily going to https://classic.demo.plone.org/en/, add a relationchoice field to the Document CT using the CT control panel, then edit a page and try to use it. You can choose only current folder items.
This behaviour is very hard to fix (no test to see how it should work) so, after reading the code and trying to understand how things works, I've found this solution:
In the xml model (you can edit TTW in the CT control panel -> the type -> model editor):
<field name="myfield" type="z3c.relationfield.schema.RelationChoice">
<description></description>
<required>False</required>
<title>My Field</title>
<form:widget type="mymodule.custom.MyFieldWidgetFactory"/>
</field>
and in custom.py
:
@adapter(schema.interfaces.IField, form.interfaces)
@implementer(form.interfaces.IFieldWidget)
def MyFieldWidgetFactory(field, request):
"""
A special widget constructor setting up widget parameters for RelatedItemsField
"""
widget = RelatedItemsFieldWidget(field, request)
widget.vocabulary_override = True
return widget
Maybe there's an xml only solution, like a vocabulary_override
tag inside form:widget and no type set but I've not time to find out. I've written more details on the problem in the #classic-ui
Discord channel.