Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Plone automatic content generation following folder generation

I was asked to implement the following on my Plone installation:

After a user created a new folder, he should be forwarded to the creation of a new page which should then be the default view of the folder.

I tried to achieve that using content rules, but unfortunately such behavior is not supported there.

What is your suggestion of achieving that behavior?

like image 231
Waynebird Avatar asked Aug 16 '26 10:08

Waynebird


2 Answers

The following should be a solution for your Problem

Define an Eventhandler in events.py

def notifyFolderIsAdded(folder, event):
    folder.REQUEST.RESPONSE.redirect(folder.absolute_url() + "/++add++Document")

Register the EventHandler in configure.zcml

<subscriber
   for="plone.app.contenttypes.interfaces.IFolder
        zope.lifecycleevent.interfaces.IObjectAddedEvent"
   handler=".events.notifyFolderIsAdded" />

Look at Events and Event Handlers in Plone Docs.

like image 179
1letter Avatar answered Aug 18 '26 00:08

1letter


I think @Ida's idea is a good solution that your customer might go for. It's quite quick to do it Dexterity when you know how.

We will do the following:

  • add a Rich Text field to the original Folder type (or a Clone of the Folder type if you prefer) via the RichText behavior
  • allow that Folder type to use document_view - a view normally used just by Pages/Documents.
  • default the Folder type to use that document_view

Add the following to your Plone addon at my.addon/my/addon/profiles/default/types/Folder.xml:

<?xml version="1.0"?>
<object name="Folder" meta_type="Dexterity FTI" i18n:domain="plone"
   xmlns:i18n="http://xml.zope.org/namespaces/i18n">

  <!-- View information -->
  <property name="default_view">document_view</property>
  <property name="view_methods" purge="False">
    <element value="document_view" />
  </property>

  <property name="behaviors" purge="False">
    <element value="plone.app.contenttypes.behaviors.richtext.IRichText"/>
  </property>

</object>

Then stick this in any configure.zcml (I used the one in the browser folder, but I'm pretty sure it doesn't matter) in the same addon:

<configure package="plone.app.contenttypes.browser">
  <browser:page
      name="document_view"
      for="plone.app.contenttypes.interfaces.IFolder"
      template="templates/document.pt"
      layer="plone.app.contenttypes.interfaces.IPloneAppContenttypesLayer"
      permission="zope2.View"
      menu="plone_displayviews"
      title="View as Document"
      />
</configure>

The issue with taking things this way, is if the customer wants to revert things to normal Plone behaviour, then they will need to copy the Rich Text out of every Folder into a new Page.

By the way you can set purge="False" for the view_methods property in Folder.xml to stop users selecting any other view for Folders.

like image 36
Danimal Avatar answered Aug 18 '26 00:08

Danimal



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!