RelatedItemsWidget and plone.app.multilingual

I have a site with plone.app.multilingual installed and I`d like to use the RelatedItems widget. If I just start typing into the Search Section (keul called it so - About the new Plone 5 "Related Items" widget) everything works as expected. But if I try to narrow the search by using the Explore Section no item is show anymore.

If you would like to reproduce it:

  • create a site
  • install plone.app.multilingual
  • configure 2 languages
  • create a page in a language root folder (e.g. start)
  • create a folder in this language root folder (e.g. folder1)
  • create another page in this subfolder (e.g. folder1/page1)
  • edit the first page (start) - go to categorization tab
  • type page1 to relateditems widget => page1 item is displayed
  • click top left icon of the relateditem widget to select a folder
  • select folder1 in your language folder
  • it says "no matches" found => but I would expect to see page1 here

I have found out, that in the second case the catalog is called with a wrong path parameter in plone.app.vocabularies - catalog.py:

{u'path': {'query': [u'/testrelateditemswidget/en/en'], 'depth': 1}, 'sort_on': u'sortable_title', 'sort_order': 'ascending'}

There is two times en in the path.

Now I have no idea what is the source of this problem - is it plone.app.multilingual because it only occurs if it is installed. Or plone.app.vocabulary? Or something else?

tested versions:

plone.app.multilingual 3.0.16 and 4.0.2
plone.app.vocabularies 2.2.3 and 3.0
plone.app.querystring 1.3.14 and 1.3.15
plone.app.content 3.1.1

I hope someone can help.

Hey! It's a trademark! :smile:

I think you found a bug, try to report it to plone.app.multilingual issue tracker.

Hello everybody,

a very belated reply to this post, as I was bitten by the same bug a few days ago. Plone 5.2.4, Python 2.7 (if that is relevant).

Context

I wanted to add (from the control panel) an "image" field to the Dexterity schema of the "Page" portal type, as a RelationChoice field pointing to image objects stored in a Plone folder. Long story short, I observed exactly the problem you described, PAM seems make the widget unusable.

Exploration

A couple of weeks ago, I had created two new portlet types, each containing RelationChoice fields and, probably by chance, I had been able to have them work correctly, without even being aware of the problem with PAM.

So, I tried to compare both situations. Using the development tools in Firefox, I was able to notice that the widget in my Page objects was using the @@getSource view in its AJAX queries, whereas the widget in my portlets was using @@getVocabulary.

Everything seems to happen in file plone.app.z3cform:widget.py, the Pycharm debugger was a great help for pinpointing the problem. I've not been able to understand the "why", but at least I understand the "how".

My portlets use the following code:

    image = RelationChoice(
        title=_(u'Image'),
        description=_(u'Find the image'),
        vocabulary='plone.app.vocabularies.Catalog',
        required=True,
    )
    directives.widget(
        "image",
        RelatedItemsFieldWidget,
        pattern_options={'selectableTypes': ['Image']},
    )

    link = RelationChoice(
        title=_(u'Link'),
        description=_(u'Find the content to link'),
        vocabulary='plone.app.vocabularies.Catalog',
        required=False,
    )

As a result, the widgets in the portlets receive a vocabularyName attribute, which resuls in their using @@getVocabulary.

In contrast, the widget in my Page objects receives None in that attribute, and the view is changed to @@getSource. This happens despite my trying to provide a <vocabulary> or <vocabularyName> in the XML definition of the schema.

Conclusion

As a workaround, I will try to subclass the widget (plone.app.z3cform.widgets.RelatedItemsWidget) and try to force the vocabularyNameattribute to 'plone.app.vocabularies.Catalog'. It should be done today.

Hope this helps,

Laurent.

Followup:

I've created my new widget (base on code from plone.app.z3cform:widget.py):

from plone.app.z3cform.widget import RelatedItemsWidget
from z3c.form.interfaces import IFieldWidget
from z3c.form.widget import FieldWidget
from zope.interface import implementer

@implementer(IFieldWidget)
def RelatedItemsFieldWidget(field, request, extra=None):
    if extra is not None:
        request = extra
    field.vocabularyName = 'plone.app.vocabularies.Catalog'
    return FieldWidget(field, RelatedItemsWidget(request))

And I've added it to the XML definition of my field:

<field name="image" type="z3c.relationfield.schema.RelationChoice"
       form:widget="xxx.yyy.widget.RelatedItemsFieldWidget">

Everything seems to work now :champagne: :champagne: :champagne:

Could you share 'all your code' (configure.zcml (etc)) ?