Collective.collectionfilter adapter issues

I am trying to add filtering on my own dexterity type's custom field on freshly installed Plone 5.1. My steps:

  • Installed collective.collectionfilter by adding it to buildout.cfg's eggs

  • Added my Dexterity content type through the web - entered several fields, one of them has short title type_of_dish (choice field, 2 possible options).

  • Created a collection named "Folder", added an instance of my content type under the folder

  • Navigated to ZMI -> portal_catalog -> Indexes, selected FieldIndex, entered Id - type_of_dish, Indexed attributes -> type_of_dish, clicked add and reindexed.

  • Created an add-on using mrbob from an addon template, created an adapter as per collective.collectionfilter's documentation. Contents of filter_test/adapters/filter_adapter.py:

          from collective.collectionfilter.interfaces import IGroupByModifier, IGroupByCriteria
          from zope.component import adapter
          from zope.interface.declarations import implementer
          
          
          @implementer(IGroupByModifier)
          @adapter(IGroupByCriteria)
          def groupby_modifier(groupby):
              groupby._groupby["type_of_dish"] = {
                  "index": "type_of_dish",
                  "metadata": "type_of_dish",
                  "display_modifier": lambda it: it
              }
    

Also added this line in configure.zcml configure tag:

<adapter factory=".adapters.filter_adapter.groupby_modifier" name="modifier_1" />

Added a portlet to my Folder, selected Current path as Folder, group-by - type_of_dish, which appeared after I installed my adapter. After saving the portlet shows an error, the (part of) traceback in console is

Traceback (innermost last):
  Module plone.app.portlets.manager, line 54, in safe_render
    Module Products.Five.browser.pagetemplatefile, line 125, in __call__
    Module Products.Five.browser.pagetemplatefile, line 59, in __call__
    Module zope.pagetemplate.pagetemplate, line 137, in pt_render
    Module five.pt.engine, line 98, in __call__
    Module z3c.pt.pagetemplate, line 163, in render
    Module chameleon.zpt.template, line 261, in render
    Module chameleon.template, line 191, in render
    Module chameleon.template, line 171, in render
    Module 6a36905592c24c23c99c377a9a5a2126.py, line 232, in render
    Module five.pt.expressions, line 161, in __call__
    Module collective.collectionfilter.baseviews, line 88, in results
    Module plone.memoize.volatile, line 73, in replacement
    Module collective.collectionfilter.filteritems, line 117, in get_filter_items
  TypeError: ('Could not adapt', <Folder at /ezonus/aplankas>, <SchemaClass plone.app.contenttypes.behaviors.collection.ICollection>)

What am I missing? Am I doing it the right way?

Right now you have to assign the portlets to a collection context ... this could be filed as an issue in the issue tracker of collective.collectionfilter nah sorry, just read your post once again. you said you selected a Folder as current path? you have to select a Collection which has to be filtered as relation ... or you use tiles with a mosaic page. but then you have to read my advice here https://github.com/collective/collective.collectionfilter/tree/petschki-mapfilter#mosaic-integration

Some more notes:

I've created an issue, that the selectable types should be "Collections" only https://github.com/collective/collective.collectionfilter/issues/43

My field did not appear in group-by selector, that's why I wrote the adapter. I have just started working on Plone/Zope and it's still quite overwhelming for me. I see "add metadata" in tutorials, but how do I actually add it? Is it field metadata, collection metadata or some different metadata? Do I enter it through the web or in some config? What metadata do I have to enter? It would be ideal if I did not have to write an add-on just to do what I stated in the original question.

without writing a custom adapter, your new group-by field appears only if you have a catalog index and a metadata with the same name. more info regarding catalog indexes and metadata is here https://docs.plone.org/develop/plone/searching_and_indexing/indexing.html#creating-a-metadata-column ... it's basically going to the metadata tab in portal_catalog and enter the same name as your index has. or in an integrator package create the catalog.xml file in your default profile with the <column /> information ... details are all on the link above.

Adding the field in portal_catalog -> Metadata solved it, thank you. The documentation tells to do this via xml and I have no idea where the xml file is; this tutorial doesn't tell that either; I didn't need any programming to make the field searchable, but the documentation page is under "Programming with Plone". All of those are misleading in every way possible.

Plone Foundation Code of Conduct