I was looking for solution how to place comments form below weblog entry in eZ publish so I decide to create custom action. I will try to explain how to define custom Action in eZ publish which create new comment object.
In example extension (ezcomment) with new action which create new comment directory structure looks like:
extension/ezcomments | | - actions | | - content_actionhandler.php | - settings | | - content.ini.append.php
You will have to override content.ini in your extension and add
extension/mynewextension/settings/content.ini.append.php
[ActionSettings]
ExtensionDirectories[]=mynewextension
For ezcomments extension this will be extension/ezcomments/settings/content.ini.append.php with code:
<?php /* [ActionSettings] ExtensionDirectories[]=ezcomments */ ?>
Body of new custom action must be placed in:
extension/mynewextension/actions/content_actionhandler.php
This is general structure of new Action:
<?php function mynewextension_ContentActionHandler( &$module, &$http, &$objectID ) { if( $http->hasPostVariable("CustomAction") ) { //your custom action goes here } } ?>
Function name have to start with extension name, other ways it will not work
In ezcomments example code will look more complex, since it will create new comment object.
code from extension/ezcomments/actions/content_actionhandler.php
<?php include_once( 'lib/ezutils/classes/ezoperationhandler.php' ); function eZComments_ContentActionHandler( &$module, &$http, &$objectID ) { if( $http->hasPostVariable( 'AddComment' ) ) { // fetch object and read node ID $object =& eZContentObject::fetch( $objectID ); $nodeID = $object->attribute( 'main_node_id' ); // read user variable $subject = $http->postVariable( 'Subject' ); $author = $http->postVariable( 'Author' ); $message = $http->postVariable( 'Message' ); // prepare new object data $parentNodeID = $nodeID; $userID = 10; $class = eZContentClass::fetchByIdentifier( 'comment' ); $parentContentObjectTreeNode = eZContentObjectTreeNode::fetch( $parentNodeID ); $parentContentObject = $parentContentObjectTreeNode->attribute( 'object' ); $sectionID = $parentContentObject->attribute( 'section_id' ); $contentObject =& $class->instantiate( $userID, $sectionID ); $contentObjectID = $contentObject->attribute( 'id' ); $nodeAssignment =& eZNodeAssignment::create( array( 'contentobject_id' => $contentObject->attribute( 'id' ), 'contentobject_version' => $contentObject->attribute( 'current_version' ), 'parent_node' => $parentContentObjectTreeNode->attribute( 'node_id' ), 'is_main' => 1 ) ); $nodeAssignment->store(); $contentObjectAttributes =& $contentObject->contentObjectAttributes(); $loopLenght = count( $contentObjectAttributes ); // fill up content object attributes with user data for( $i = 0; $i < $loopLenght; $i++ ) { switch( $contentObjectAttributes[$i]->attribute( 'contentclass_attribute_identifier' ) ) { case 'subject': $contentObjectAttributes[$i]->setAttribute( 'data_text', $subject ); $contentObjectAttributes[$i]->store(); break; case 'author': $contentObjectAttributes[$i]->setAttribute( 'data_text', $author ); $contentObjectAttributes[$i]->store(); break; case 'message': $contentObjectAttributes[$i]->setAttribute( 'data_text', $message ); $contentObjectAttributes[$i]->store(); break; } } $contentObject->setAttribute( 'status', EZ_VERSION_STATUS_DRAFT ); $contentObject->store(); // publish new comment $operationResult = eZOperationHandler::execute( 'content', 'publish', array( 'object_id' => $contentObjectID, 'version' => 1 ) ); // redirect to weblog full view $module->redirectTo( '/content/view/full/' . $nodeID ); } } ?>
The simplest form for new custom action will look like:
<form method="post" action={"content/action"|ezurl}>
<input type="submit" name="CustomAction" value="Custom action" />
<input name="ContentObjectID" type="hidden" value="102" />
</form>
ContentObjectID have to be included in POST.
In ezcomments extension example from will include Subject, Author and Message input fields. Code blow can be placed in weblog_full.tpl. User will see form which can use for posting new comment:
<form method="post" action={"content/action"|ezurl}>
Subject: <input type="text" name="Subject" value="" /><br />
Author: <input type="text" name="Author" value="" /><br />
Message: <textarea name="Message"></textarea><br />
<input type="submit" name="AddComment" value="Submit" />
<input name="ContentObjectID" type="hidden" value="{$node.object.id}" />
</form>
That's all. We have new action that create new comment under weblog object. Code from content_actionhandler.php (ezcomments) need of course some additional checking for incoming data, validation, etc. but shows how custom action works in the eZ publish.
No trackbacks.
eZ publish is a open source enterprise content management system and development framework with functionality for web publishing, intranets, e-commerce and more.


As Microsoft Silverlight technology is becoming increasingly popular, it will be supported in the upcoming eZ Publish 4.1 release. Sites using the Website Interface and eZ Flow will include a Silverlight class and the corresponding view templates. Simply upload .xap files (compressed Silverlight package) as attributes in Silverlight objects; when such an object is viewed by a site visitor, your Silverlight media is loaded in the web browser (provided that the visitor has the Silverlight browser plugin installed). This is similar to how eZ Publish already supports .swf files via the Flash class. More information will be available as the next eZ Publish release date approaches.
eZ Publish developer day in Warsaw, Poland - 15th April 2008I happy to announce first eZ Publish developer day that will be held in Warsaw in Poland on 15th of April 2008. First time eZ goes to Poland ;) eZ Publish developer day is community-driven event and open for all attendees. Agenda will be settled at the event by the attendees. Some discussions will be in English.
Roadmap for eZ Publish 4.1 and 4.5A roadmap for the next eZ Publish releases is now available. eZ Publish 4.1, the next major release, will include the new Online Editor, as was previously mentioned in Community Newsletter #1/2008. The new Online Editor will have various enhancements regarding usability and the user interface, and will support Internet Explorer 7 for Windows Vista. eZ Publish 4.1 is expected to be released in the first quarter of 2008.
Small enhancement