-->

How to add new collection criteria in Plone 5?

2019-07-14 13:34发布

问题:

I add a new choice field named course to Dexterity Content Type File in a new created instance. In order to use the field "course" as criteria in /++add++Collection, I follow this guide and add these to the file registry.xml in plone/buildout-cache/eggs/plone.app.querystring-1.3.14-py2.7.egg/plone/app/querystring/profiles/default/registry.xml:

<records interface="plone.app.querystring.interfaces.IQueryField"
       prefix="plone.app.querystring.field.course">
<value key="title">course</value>
<value key="description">A custom course index</value>
<value key="enabled">True</value>
<value key="sortable">False</value>
<value key="operations">
    <element>plone.app.querystring.operation.string.is</element>
</value>
<value key="group">Metadata</value>
</records>

But I can not find "course" in criteria list.

What can I do to get this criteria for collection?

回答1:

First of all: modify the Plone source code is a bad practice. Don't do it. Never.

The guide you are referring to is OK, but it's intended to be used in a new Plone add-on you must develop and add to your installation.

Please read the "Develop Plone Add ons" guide.

In your case: you need a really simple add-on with a simple generic setup step that contains a registry.xml file with your code above. After installing the add-on (and every time you will reinstall it) your registration will be added to your site.