Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RelatedItems field added TTW does not work correctly inside a navigation root #214

Open
yurj opened this issue Nov 15, 2024 · 0 comments
Open

Comments

@yurj
Copy link

yurj commented Nov 15, 2024

# widget vocab takes precedence over field
form_url = self.request.getURL()
source_url = "{:s}/++widget++{:s}/@@getSource".format(
form_url,
self.name,
)
pattern_options["vocabularyUrl"] = source_url

after adding a RelatedItems field in dexterity content type control panel (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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant