Z3c.form Display Template override, RelationList/RelatedItemsFieldWidget

With Mosaic I can use the plone.app.standardtiles.field tile to edit and show fields from a schema (in my case a behavior, but it does not matter).

Then, I can also register an alternate template (for display with z3c.form), like it is done already for i.e. the title field and other display templates here: plone.app.standardtiles/field.py at ef456b73545144209101bc819dc15c12ae1dc02f · plone/plone.app.standardtiles · GitHub

This is standard z3c.form display template override, so nothing special to Mosaic.

The problem starts if it comes to a RelationList with its widget like so:

    widget(
        "slider_images",
        RelatedItemsFieldWidget,
        pattern_options={
            "selectableTypes": ["Image"],
            "favorites": make_image_favorites,
            "upload": utils.allow_upload,
            "uploadAllowView": utils.make_allow_upload_url,
            "scanSelection": True,
            "recentlyUsed": True,
            "recentlyUsedKey": utils.recently_used_common_key,
        },
    )
    slider_images = RelationList(
        title=_("label_sliderimages", default="Slider Images"),
        value_type=RelationChoice(
            title=_("label_slidersimage", default="Slider Image"),
            vocabulary="plone.app.vocabularies.Catalog",
        ),
        required=False,
    )

if I then provide a template in the same way as above, like so:

slider_images_display_template = ViewPageTemplateFile(
    "sliderimages_tile_display.pt", content_type="text/html"
)

@implementer(IPageTemplate)
@adapter(
    None,
    ITilesFormLayer,
    DexterityFieldTile,
    getSpecification(ISliderImages["slider_images"]),
    RelatedItemsFieldWidget,
)
def slider_images_display(context, request, form, field, widget):
    return slider_images_display_template

and register it in ZCML

  <adapter
      factory=".sliderimages.slider_images_display"
      name="display"
      />

I got on startup

Traceback (most recent call last):
  File "/home/jensens/ws/pro/akbild/portal/venv/lib/python3.9/site-packages/zope/configuration/config.py", line 792, in execute_actions
    callable(*args, **kw)
  File "/home/jensens/ws/pro/akbild/portal/venv/lib/python3.9/site-packages/zope/component/zcml.py", line 55, in handler
    method(*args, **kwargs)
  File "/home/jensens/ws/pro/akbild/portal/venv/lib/python3.9/site-packages/zope/interface/registry.py", line 306, in registerAdapter
    required = _getAdapterRequired(factory, required)
  File "/home/jensens/ws/pro/akbild/portal/venv/lib/python3.9/site-packages/zope/interface/registry.py", line 618, in _getAdapterRequired
    raise TypeError("Required specification must be a "
TypeError: Required specification must be a specification or class, not <class 'function'>

Which is caused by RelatedItemsFieldWidget, which is indeed a function:

(Pdb++) RelatedItemsFieldWidget
<function RelatedItemsFieldWidget at 0x7f680230a820>

I thought I am clever and grep the value from the widget itself like so

@adapter(
    # ...snip, see above
    ISliderImages.queryDirectTaggedValue(WIDGETS_KEY)["slider_images"].__class__,
)

This is a plone.autoform.widgets.ParameterizedWidget class

Startup does not fail, but the adapter does not get grip. So, not clever enough.

Any idea how to override the display widget of a RelationList/RelatedItemsFieldWidget?

Looks like in p.a.standardtiles the widgets are used, and not the IFieldWidget functions. Try the RelatedItemsWidget.

I forgot to tell, I tried this already and it does not get grip too. But you're right. It's one tile in the puzzle.

I dug a whole level deeper and got it working in a more z3c-formish way than its done in plone.app.standardtiles:

SLIDER_IMAGE_FIELD_SPEC = getSpecification(ISliderImages["slider_images"])
  <z3c:widgetTemplate
      mode="display"
      field=".sliderimages.SLIDER_IMAGE_FIELD_SPEC"
      widget="plone.app.z3cform.interfaces.IRelatedItemsWidget"
      layer="plone.app.tiles.interfaces.ITilesFormLayer"
      template="sliderimages_tile_display.pt"
      />
1 Like

Plone Foundation Code of Conduct