Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to directly publish only child items of my Container type in Plone?

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

I can achieve this easily by setting an appropriate workflow for the Document type, but that would affect every document in my site. I want only the ones inside my container type to be directly published.

Two options come to my mind:

Custom page

Create basically just a copy of the stock Document type and set its workflow to something that has only published state.

Event

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

Neither sounds too nice. Do I have other options?

like image 674
Epeli Avatar asked Jul 13 '11 13:07

Epeli


3 Answers

You just want the "Workflow Policy Support (CMFPlacefulWorkflow)" product (it's a default part of Plone):

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

You can set workflow on individual folders, or on that folder and all folders below it.

like image 74
Auspex Avatar answered Oct 21 '22 11:10

Auspex


Create a new automatic transition in the workflow you're using that has the guard:

python:container.meta_type == 'ATFolder'

this will then only fire if the parent object is of the standard 'Folder' type (note the meta type and the type name are not the same).

The downside of this is that it will be fired relatively early in the creation process, so the user will see an error message if they haven't got enough permissions to finish creation on the published object.

If this doesn't meet what you want I think the Event is your closest bet.

like image 34
MatthewWilkes Avatar answered Oct 21 '22 12:10

MatthewWilkes


Use an event subscriber to trigger an automatic workflow transition (for example by subscribing to the IObjectInitializedEvent and checking for IYourDexterityFolderishType.providedBy(aq_parent(obj)) - see plone community developer docs)

like image 2
Christoph Böhner Avatar answered Oct 21 '22 12:10

Christoph Böhner