Inherit behaviors

Contents

Inherit behaviors#

Plone content items are arranged in a hierarchy. Each content item has a parent, each of which may have its own parent, continuing all the way to the Plone site root. Together, the chain of parents are ancestors of the content item.

The @inherit service makes it possible to access data from a behavior defined on one of these ancestors.

Tip

Inheriting behaviors is similar to the concept of acquisition in Zope, but it doesn't happen automatically, so it's safer.

To use the service, send a GET request to the @inherit endpoint in the context of the content item that is the starting point for inheriting. Specify the expand.inherit.behaviors parameter as a comma-separated list of behaviors.

http

GET /plone/document/@inherit?expand.inherit.behaviors=plone.navigationroot HTTP/1.1
Accept: application/json
Authorization: Basic YWRtaW46c2VjcmV0

curl

curl -i -X GET 'http://nohost/plone/document/@inherit?expand.inherit.behaviors=plone.navigationroot' -H "Accept: application/json" --user admin:secret

httpie

http 'http://nohost/plone/document/@inherit?expand.inherit.behaviors=plone.navigationroot' Accept:application/json -a admin:secret

python-requests

requests.get('http://nohost/plone/document/@inherit?expand.inherit.behaviors=plone.navigationroot', headers={'Accept': 'application/json'}, auth=('admin', 'secret'))

For each behavior, the service will find the closest ancestor which provides that behavior. The result includes from (the @id and title of the item from which values were inherited) and data (values for any fields that are part of the behavior).

HTTP/1.1 200 OK
Content-Type: application/json

{
    "inherit": {
        "@id": "http://localhost:55001/plone/document/@inherit?expand.inherit.behaviors=plone.navigationroot",
        "plone.navigationroot": {
            "data": {},
            "from": {
                "@id": "http://localhost:55001/plone",
                "title": "Plone site"
            }
        }
    }
}

Ancestor items for which the current user lacks the View permission will be skipped.

Expansion#

This endpoint can be used with the Expansion mechanism which allows getting more information about a content item in one query, avoiding unnecessary requests.

You can make a GET request for a content item, and include parameters to request inherit expansion for specific behaviors:

http

GET /plone/document/?expand=inherit&expand.inherit.behaviors=plone.navigationroot HTTP/1.1
Accept: application/json
Authorization: Basic YWRtaW46c2VjcmV0

curl

curl -i -X GET 'http://nohost/plone/document/?expand=inherit&expand.inherit.behaviors=plone.navigationroot' -H "Accept: application/json" --user admin:secret

httpie

http 'http://nohost/plone/document/?expand=inherit&expand.inherit.behaviors=plone.navigationroot' Accept:application/json -a admin:secret

python-requests

requests.get('http://nohost/plone/document/?expand=inherit&expand.inherit.behaviors=plone.navigationroot', headers={'Accept': 'application/json'}, auth=('admin', 'secret'))

The response will include data from the @inherit endpoint within the @components property:

HTTP/1.1 200 OK
Content-Type: application/json

{
    "@components": {
        "actions": {
            "@id": "http://localhost:55001/plone/document/@actions"
        },
        "aliases": {
            "@id": "http://localhost:55001/plone/document/@aliases"
        },
        "breadcrumbs": {
            "@id": "http://localhost:55001/plone/document/@breadcrumbs"
        },
        "contextnavigation": {
            "@id": "http://localhost:55001/plone/document/@contextnavigation"
        },
        "inherit": {
            "@id": "http://localhost:55001/plone/document/@inherit?expand.inherit.behaviors=plone.navigationroot",
            "plone.navigationroot": {
                "data": {},
                "from": {
                    "@id": "http://localhost:55001/plone",
                    "title": "Plone site"
                }
            }
        },
        "navigation": {
            "@id": "http://localhost:55001/plone/document/@navigation"
        },
        "navroot": {
            "@id": "http://localhost:55001/plone/document/@navroot"
        },
        "types": {
            "@id": "http://localhost:55001/plone/document/@types"
        },
        "workflow": {
            "@id": "http://localhost:55001/plone/document/@workflow"
        }
    },
    "@id": "http://localhost:55001/plone/document",
    "@type": "Document",
    "UID": "SomeUUID000000000000000000000002",
    "allow_discussion": false,
    "changeNote": "",
    "contributors": [],
    "created": "1995-07-31T13:45:00+00:00",
    "creators": [
        "test_user_1_"
    ],
    "description": "",
    "effective": null,
    "exclude_from_nav": false,
    "expires": null,
    "id": "document",
    "is_folderish": false,
    "language": "",
    "layout": "document_view",
    "lock": {
        "locked": false,
        "stealable": true
    },
    "modified": "1995-07-31T17:30:00+00:00",
    "next_item": {},
    "parent": {
        "@id": "http://localhost:55001/plone",
        "@type": "Plone Site",
        "description": "",
        "title": "Plone site",
        "type_title": "Plone Site"
    },
    "previous_item": {},
    "relatedItems": [],
    "review_state": "private",
    "rights": "",
    "subjects": [],
    "table_of_contents": null,
    "text": null,
    "title": "Test document",
    "type_title": "Page",
    "version": "current",
    "versioning_enabled": true,
    "working_copy": null,
    "working_copy_of": null
}