Forums / Developer / Defining "methods" or "custom actions" for content classes?

Defining "methods" or "custom actions" for content classes?

Author Message

Deane Barker

Wednesday 07 December 2005 12:09:19 am

Is it possible to define methods on a content class? By "method," I mean is it possible to define something that content object will <i>do</i>, on demand?

Example --

Our users can create newsletters in eZ. A newsletter is a content class. It would be nice if -- after they've created and edited the newsletter -- that they could hit a button on the interface that said "Send This," and then eZ would run some PHP code that would send it.

I know you can do things in workflow, but that's not quite what we're looking for. We'd really just like some buttons on the interface that let the users "command" objects to do things.

In the admin templates, I've seen an iteration for "Custom Actions" which seems to generate some buttons, but I've never seen this referred to anywhere else.

Deane

Ɓukasz Serwatka

Wednesday 07 December 2005 12:27:30 am

It is possible to create custom actions in eZ publish. By default it comes with several like, creating new content, editing, collecting information and more.

You can place new actions in extension/mynewextension/actions/content_actionhandler.php

You will have to override content.ini in your extension and add
extension/mynewextension/settings/content.ini.append.php

[ActionSettings]
ExtensionDirectories[]=mynewextension

extension/mynewextension/actions/content_actionhandler.php

function name have to start with extension name, other ways it will not work

function mynewextension_ContentActionHandler( &$module, &$http, &$objectID )
{
    if( $http->hasPostVariable("CustomAction") )
    {
        //your custom action goes here
    }
}

In tpl you will need define form:

<form method="post" action="content/action">
    <input type="submit" name="CustomAction" value="Custom action" />
    <input name="ContentObjectID" type="hidden" value="102" />
</form>

ContentObjectID have to be included in POST.

For more examples look in to /kernel/content/action.php. I think you can re-use some code.

Hope it will help you.

Personal website -> http://serwatka.net
Blog (about eZ Publish) -> http://serwatka.net/blog

Deane Barker

Wednesday 07 December 2005 5:55:12 am

Wonderful, thank you. I remember seeing that one line of template code ages ago, but I could never find any documentation on it. This is fantastic.

Andrew K

Tuesday 18 July 2006 6:59:37 am

Yup. That's what I'm looking for!
Thanks.

--Andrew