How to directly publish only children of my container type in Plone?

I have a custom Dexterity content type in Plone. He can only have documents as children. I want these documents to be directly published as they are created.

I can easily achieve this by setting the appropriate workflow for the Document type, but this will affect every document on my site. I want only those that were inside my container type to be published directly.

Two options come to me:

User page

Create basically only a copy of the stock document type and set its workflow to only the published state.

Event

Add an IObjectAdded event for Documents and check if the parent of the new document is my container type and does manual publishing in python code.

Nothing is too good. Do I have any other options?

+8
python workflow plone
source share
3 answers

You just need the Workflow Policy Support (CMFPlacefulWorkflow) product (this is the default part of Plone):

Add in Plone the capability to change workflow chains for types in every object. 

You can set the workflow in separate folders or in this folder and in all folders below.

+10
source share

Create a new automatic transition in the workflow you are using with protection:

python:container.meta_type == 'ATFolder'

then this will only work if the parent object has the standard type "Folder" (note that the meta type and type name do not match).

The disadvantage of this is that it will be launched relatively early in the creation process, so the user will see an error message if they do not have enough authority to complete the creation of the published object.

If this does not match what you want, I think this is your closest bet.

+4
source share

Use an event subscriber to start an automatic transition of a workflow (for example, subscribing to IObjectInitializedEvent and checking for IYourDexterityFolderishType.providedBy(aq_parent(obj)) ) - see plon community docs )

+2
source share

All Articles