Project: powercontent

Power Content

Normally whenever new content is created, the system automatically creates and stores a new draft version of the object, before presenting it to the user for initial editing and publishing.  If the content is being created from the Admin siteaccess or for example the user/register view, this is fine as the user would have explicitly decided to click on a 'Create Here' or 'Register' button before being presented with a content-edit view for adding their content.  However, where we know what content type will be used but not when, it is often desireable for a front-end view of a site to have an empty content-entry from ready and waiting for the visitor/user to just enter some content and click 'Submit'.  For example to have an Article and below it, a comment entry form ready for completion.  If we try to do that with the default behaviour of eZ Publish we would be creating a blank draft comment every time the page was viewed.  Although, there are cronjobs which routinely dispose of unused drafts, it is still not a good idea to use this behaviour in these cases, especially on a busy site, creating dozens or hundreds of abandoned drafts per day.  

The 'Power Content' extension solves this issue in a way that complements the normal behaviour of eZ Publish.  This is a very popular and useful extension.  It provides a way to have a standard HTML form on the webpage that submits its data to a custom-module, which in turn uses that content to create and submit the object for publishing.  So, even though there is a form ready for input every time the page is viewed, no draft or published object is created until after its data has been input by the user and the Submit button pressed.  Core eZ Publish continues to behave as normal but this extension acts as a messenger to that normal behaviour.  And the extension works with all content-classes and all content-class-attribute types, including any custom types.  Use this extension whenever you know the content type to be created, want an input form present and ready to accept content, but don't want a draft to have been automatically created.

The Power content module allows one-click publishing or pre-filling of attributes, similar to the Object Creator extension.

However, it uses content/edit for the final processing. This module has one big advantage: it can deal with any type of attribute, even new custom ones.

Documentation

Compatibilty

3.10, 4.0

Usage

Installation instructions

1. Enable the extension (in site.ini.append or by using the admin interface)
 2. Add a policy for this module to the desired roles.

How to use in your template

The main idea is to add new attributes that are going to contain the values you want instead of the default ones on ez publish. This module associate these new fields with standard fields that exist when editing with the default edit template. Therefore, you have to understand how ez names these fields so you can add the values you want.

A typical naming scheme for the input fields of an attribute is:

ContentObjectAttribute_[some attribute specific name]_[contentobjectattribute id]

For instance the name for the fields of an articles are (do a view source of the page when you're editing an article):

- title: ContentObjectAttribute_ezstring_data_text_1105
 - into: ContentObjectAttribute_data_text_1108

(1105 and 1108 are contentobjectattribute identifier numbers that are going to be different on your installation.)

You will have to to change these names to:

powercontent_[contentclassattribute identifier]_ContentObjectAttribute_[some attribute specific name]_pcattributeid 

For the article, it would be:

-title: powercontent_title_ContentObjectAttribute_ezstring_data_text_pcattributeid
 -intro: powercontent_intro_ContentObjectAttribute_data_text_pcattributeid
 When the Power Content module processes this kind of post variables, it will take their content and put them into the proper fields as if the user would have inputed it (it will inject fake post variables where the string "pcattributeid" will be replaced by the expected contentobjectattribute id).
 On the top of the parameters you want to "prefill", you have to provide a few additional ones:

  •  NodeID: The nodeid of the parent object you want to create (as an option, you can put "UserNode", that will put create it under the usernode of the currently logged in user)
  •  ClassIdentifier: The class identifier of the object you want to create (you can provide either the class identifier or the class id, no need for both)
  •  CreateButton: a submit button

You have more optional parameters:

  •  RedirectToMainNodeAfterPublish: if you have installed and enabled the redirect extension, then you can use this post variable to redirect to the main node of the newly created object after publishing it.

powercontent_attribute_create_gui function

The powercontent_attribute_create_gui eases the process of creating the attribute input fields with the correct names for the powercontent extension.

Example of its usage:

{powercontent_attribute_create_gui class_attribute=$folderClass.data_map.name}

Currently there are templates included for the following datatypes:

  •  Checkbox
  •  Country
  •  Date
  •  E-mail
  •  Enhanced selection
  •  File
  •  Float
  •  Integer
  •  URL
  •  Selection
  •  Text block
  •  Text line

Feel free to commit yours to svn.

Examples code

1) Example code for the "article" content class. This will prefill the title and intro of the article:

<form method="post" action={"powercontent/action/"|ezurl}>
  <div class="buttonright">
  <input type="hidden" name="NodeID" value="{$owner.contentobject.main_node_id}" />
  <input type="hidden" name="ClassIdentifier" value="article" />
  <input type="hidden" name="powercontent_title_ContentObjectAttribute_ezstring_data_text_pcattributeid" value="A new article on my blog" />
  <input type="hidden" name="powercontent_intro_ContentObjectAttribute_data_text_pcattributeid" value="A new intro on my blog" />
   <input class="classbutton" type="submit" name="CreateButton" value="New article" />
</div>
</form>

2) Example code for the "File" content class:

<form method="post" action={"powercontent/action"|ezurl} enctype="multipart/form-data">
    <div>
    <input type="hidden" name="NodeID" value="{$node.main_node_id}" />
    <label>Publish immediately:</label> <input type="checkbox" name="DoPublish" checked="checked" />
    <input type="hidden" name="UseNodeAssigments" value="0" />
    <input type="hidden" name="ClassID" value="12" />
    <input type="hidden" name="RedirectURIAfterPublish" value="/{$node.url_alias}" />
    </div>
    
    <div>
    <label>File:</label>
    <input class="box" name="powercontent_file_ContentObjectAttribute_data_binaryfilename_pcattributeid" type="file" />
    </div>
    <div>
    <label>Title:</label>
    <input type="text" name="powercontent_name_ContentObjectAttribute_ezstring_data_text_pcattributeid" value="" />
    </div>
    <div>
    <input class="button" type="submit" name="CreateButton" value="Create" />
    </div>
</form>
</pre>

License

Powercontent is copyright (C) 2006-2007 SCK•CEN, 2008 Kristof Coomans and is licensed under the GNU-GPL.

External reference