Skip to the content
Documentation
Help Start
Reading in:
  • German: 9,059 of 9,059 pages
About the help in other languages
All help pages

By hand: a workflow event

A workflow event type "Log publishing" by hand: the class, the registration, the view template, a workflow and a trigger, and the log line it writes.

Download as PDF

Address: https://doc.exponential.earth/exphelp/viewer/help/extension-development/part-3-extension-developer/tutorials/by-hand-workflow-event.md

On this page

By hand: a workflow event

Tutorial 15. You add an event type that writes a line to var/log/mysite_hello.log for every published version. The class passed php -l; with the kernel loaded, eZWorkflowType::createType( 'event_mysitepublishlog' ) created it and isAllowed( 'content', 'publish', 'after' ) returned true (and false for before).

1. The class

extension/mysite_hello/eventtypes/event/mysitepublishlog/mysitepublishlogtype.php:

<?php
/**
 * Workflow event "Log publishing": writes one line per published version to var/log/mysite_hello.log.
 * Use it on the trigger content / publish / after.
 */
class mysitePublishLogType extends eZWorkflowEventType
{
    const WORKFLOW_TYPE_STRING = 'mysitepublishlog';

    public function __construct()
    {
        parent::__construct( self::WORKFLOW_TYPE_STRING,
                             ezpI18n::tr( 'extension/mysite_hello', 'Log publishing' ) );
        $this->setTriggerTypes( array( 'content' => array( 'publish' => array( 'after' ) ) ) );
    }

    public function execute( $process, $event )
    {
        $parameters = $process->attribute( 'parameter_list' );
        $objectID = isset( $parameters['object_id'] ) ? (int)$parameters['object_id'] : 0;
        $version = isset( $parameters['version'] ) ? (int)$parameters['version'] : 0;

        $object = eZContentObject::fetch( $objectID );
        if ( !$object instanceof eZContentObject )
        {
            // nothing to log; let the operation continue
            return eZWorkflowType::STATUS_ACCEPTED;
        }

        eZLog::write( sprintf( 'Published object %d version %d: %s', $objectID, $version, $object->attribute( 'name' ) ),
                      'mysite_hello.log' );

        return eZWorkflowType::STATUS_ACCEPTED;
    }
}

eZWorkflowEventType::registerEventType( mysitePublishLogType::WORKFLOW_TYPE_STRING, 'mysitePublishLogType' );

2. The registration

extension/mysite_hello/settings/workflow.ini.append.php:

<?php /* #?ini charset="utf-8"?

[EventSettings]
ExtensionDirectories[]=mysite_hello
AvailableEventTypes[]=event_mysitepublishlog

*/ ?>

3. The template the workflow editor shows

extension/mysite_hello/design/standard/templates/workflow/eventtype/view/event_mysitepublishlog.tpl:

<div class="element">
    <p>{'Log publishing'|i18n( 'extension/mysite_hello' )}</p>
</div>

An event without settings needs no edit template; add workflow/eventtype/edit/event_mysitepublishlog.tpl when it gets settings (Workflow event types).

4. Switch on and wire up

php -l extension/mysite_hello/eventtypes/event/mysitepublishlog/mysitepublishlogtype.php
php bin/php/ezcache.php --clear-all
  1. Setup > Workflows: in a workflow group, create "Log publishing", add the event "Log publishing", store.

  2. Setup > Triggers: for content / publish / after, choose the workflow, store.

  3. Publish an article, then:

    tail -n 3 var/log/mysite_hello.log

    shows a line Published object <id> version <n>: <name>.

5. Remove the trigger when done

A trigger runs for every publication on the site. When you finish experimenting, set the trigger back to no workflow.

Become an Exponential Partner

Partners share their information, provide funding, contribute back and develop the products with us, and that is how Exponential grows. A partner website and dashboard are planned for mid-2027: please become a partner today to speed up our growth rate and land new features faster.

Something wrong on this page? Report an error

Documentation license

This documentation is free documentation, licensed under the GNU Free Documentation License 1.3 or later.

Exponential Copyright © 1998-2026 Exponential Foundation and 7x