RelationList with 'start path'

I have a related items field defined with:

    relatedProjects = RelationList(
    title=_(u'label_related_items', default=u'Prosjekter'),
    default=[],
    value_type=RelationChoice(
        title=u'Prosjekter',
        source=CatalogSource(portal_type=['project']),
    ),
    required=False,
)

Which works find, but the widget 'search' starts from current folder (see screenshot).


In other words, the user needs to click on 'home' and search from there.

Is there a way to have the path default to home or some other folder?

Try with something like this:

from plone.app.z3cform.widget import RelatedItemsFieldWidget
from plone.autoform import directives

directives.widget(
        "relatedProjects",
        RelatedItemsFieldWidget,
        pattern_options={"mode": "auto", "favorites": []},
)

More possible patter options here: https://github.com/plone/mockup/blob/master/mockup/patterns/relateditems/pattern.js#L3

Thanks a lot, this seems to work

    directives.widget(
    'relatedItems',
    RelatedItemsFieldWidget,
    pattern_options={
        'basePath': '/',
        "mode": "auto",
        "favorites": []
        }
    )

In the docs, basePath should default to '/', so I am not sure what happens here.

One strange thing: When I set base path to

 'basePath': '/prosjekter',

The widget starts at '/r' (which does not exist).

That's what i do:

from zope import schema
from zope.interface import provider

from plone import api
from plone.app.z3cform.widget import RelatedItemsFieldWidget
from plone.autoform import directives
from plone.autoform.interfaces import IFormFieldProvider
from plone.supermodel import model


def basePath(context=None):    
  uid = api.portal.get_registry_record('uid_of_configurable_folder', default = None)  
  if not uid:
    # Root Portal Path
    folder = api.portal.get()
  else:
    # Folder Start Path
    folder = api.content.get(UID=uid)  
  return '/'.join(folder.getPhysicalPath())

@provider(IFormFieldProvider)
class IContact(model.Schema):

    model.fieldset(
        'contact',
        label = _(u'Contact'),
        fields = ['supervisor']
    )
    
    supervisor = schema.Choice(
        title=_(u"Supervisor"),
        description=_(u"Select the Supervisior"),
        required=True,
        vocabulary='plone.app.vocabularies.Catalog',
    )

    directives.widget(
        'supervisor',
        RelatedItemsFieldWidget,
        pattern_options={
            'selectableTypes': ['Supervisor'],
            'basePath': basePath
        }
    )
2 Likes

Is this a record you have added (never heard about it)

Am I understanding your right if:

basePath should no be /supervisors, but (for example) Plone/supervisors ?

the full path from ZMI root, yes.

The record is a custom record, not a Plone Registry Entry. It's only an example for configurable Paths :wink:

Nice one! In the same way, you can return dynamic favorites dependent on context :heart_eyes:

Plone Foundation Code of Conduct