This site has been archived. To learn more about our current products Ibexa Content, Ibexa Experience, Ibexa Commerce head over to the Ibexa Developer Portal

eZ Community » Learn » eZ Publish » Creating a simple custom workflow event

Creating a simple custom workflow event

Thursday 09 December 2010 5:01:18 pm

  • Currently 5 out of 5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Step 3 – Develop a workflow event: preparation

As an example to this tutorial we will see how to create a new workflow event that will automatically post a Twitter status update on publication of a blog post. The status message is customizable and the editor can choose not to post any.

We need to create a new folder in the existing extension/ folder. Lets call it “mytwitter”. Several sub-folders need to be created:

  • eventtypes/: this folder will host the actual code of our workflow event.
  • lib/: this folder will host 3rd party libraries needed by our eZ Publish extension.
  • settings/: some settings files.

Lets start with the “eventtypes/” folder. Inside this folder, you need to create another one and name it “event/”. It will hold all the events we want to create as part of this extension. For our extension we will have just one event so lets create a new folder and name it “twitterstatusupdate/”. You should be have ~extension/mytwitter/eventtypes/event/twitterstatusupdate/

Inside this folder, lets create our PHP file. The filename of our file must be the name of the current folder (twitterstatusupdate) and end with “type.php”. So we will need to create a file named “twitterstatusupdatetype.php”.

We will start by filling it in with an empty template for developing a workflow event:

class TwitterStatusUpdateType extends eZWorkflowEventType
    const WORKFLOW_TYPE_STRING = "twitterstatusupdate";
    public function __construct()
        parent::__construct( TwitterStatusUpdateType::WORKFLOW_TYPE_STRING, 'Update Twitter Status' );
    public function execute( $process, $event )
        $parameters = $process->attribute( 'parameter_list' );
        /*  YOUR CODE GOES HERE */
        return eZWorkflowType::STATUS_ACCEPTED;
eZWorkflowEventType::registerEventType( TwitterStatusUpdateType::WORKFLOW_TYPE_STRING, 'twitterstatusupdatetype' );

In the above code the function you are interested in is the public function execute($process, $event). This function is holding your event code and is called by eZ Publish passing two parameters $process and $event..

Lets have a quick look at what information you can retrieve from these two parameters:

  • $process is an instance of the eZWorkflowProcess class. It is holding information relative to the eZ Publish workflow process being run such as the workflow process ID, the workflow ID, the User ID under which the workflow process is executed (see for more details). This tutorial is more interested in the parameter ‘parameter_list’ accessible via $process->attribute(‘parameter_list’). This will return the an associative array with the following keys 'object_id', ‘version’, ‘workflow_id’, ‘trigger_name’, ‘module_name’, ‘module_function’, ‘user_id’, ‘parent_process_id’.
  • $event is an instance of the eZWorkflowEvent class. It is holding information relative to your workflow event. This is not useful to us at this stage.

This function should return one of several predefined values depending on the outcome of the execution of the code and what is to be done next. For example: eZWorkflowType::STATUS_ACCEPTED if we should leave the workflow process and end it, eZWorkflowType::STATUS_DEFERRED_TO_CRON if we want to defer this workflow to be processed later by a cronjob etc… See the eZWorkflowType class reference:

Our workflow event is a PHP class that extends eZWorkflowEventType class. Please note the class name must use the same name as our PHP file. In the constructor we are declaring our event and the name that will be displayed in drop down menus. The execute method is holding the actual code.



Printer Friendly version of the full article on one page with plain styles


Proudly Developed with from