Ticket #20239 (new PLIP)

Opened 14 months ago

Last modified 11 months ago

Implement API for Dexterity behaviors

Reported by: rnix Owned by: davisagli
Priority: major Milestone: 5.0
Component: Dexterity Version: 4.2
Keywords: BehaviorAPI Cc:

Description (last modified by jensens) (diff)

Proposer: Robert Niederreiter

Seconder: Jens Klein

Motivation:

Plone provides no documented and easy to understand API for dealing with behaviors of content objects.

A discussion about the subject can be found here  http://comments.gmane.org/gmane.comp.web.zope.plone.devel/34834

Proposal & Implementation:

  • Plone behaviors get a shortname under which they can be accessed via content objects (right now some needs to know the interface identifier to lookup a behavior registration)
  • Behavior registrations get a verbose repr function in order to describe the provided behavior functionality and technical details (class, id, name, identifier, title, description, provided fields, ...)
  • Dexterity content objects get a property "behaviors", which is a class instance with a call and a repr function. The repr function lists all applied behaviors (via the repr function of the corresponding behavior registration, see above) and the call function looks up the behavior registration by name (either shortname or interface identifier, both works) and return the concrete behavior.

Example usage:

    >>> basic = context.behavior('basic')
    >>> basic
    <BehaviorRegistration basic at ...
      schema: plone.app.dexterity.behaviors.metadata.IBasic
      marker: ...
      factory: ...
      title: Basic metadata
      description: Adds title and description fields
      fields:
          title: Title (zope.schema.TextLine)
          description: Summary (zope.schema.Text)
    >

    >>> title = basic.title
    >>> basic.title = u'New title'

Implications:

Existing Behavior implementations need to get a shortname in order to make registration lookup also work by shortname.

For the core this means plone.app.dexterity and plone.app.contenttypes needs to get adapted, maybe others.

Risks:

None, no B/C issues.

Maybe some test output of addons may fail due to custom repr if behavior registration instances are involved in these cases.

Participants:

  • Jens Klein
  • Robert Niederreiter

Progress:

Branches with the proposed implementation exists here:

 https://github.com/plone/plone.behavior/tree/rnixx_behavior_name_and_lookup  https://github.com/plone/plone.dexterity/tree/dx_api

Some tests are missing and the implementation of the repr functions needs to be completed/finished

Change History

comment:1 Changed 11 months ago by jensens

  • Description modified (diff)

comment:2 Changed 11 months ago by jensens

Documentation of progress moved to Github:  https://github.com/plone/Products.CMFPlone/issues/517

Note: See TracTickets for help on using tickets.