eZ Community » Blogs » Thiago Campos Viana » Tip: The minimum content action...

By

Tip: The minimum content action extension

Friday 19 August 2011 2:53:00 pm

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

In this post I will show how to create the minimum content action extension.

The 'content/action' view is commonly used to process forms - while eZ Publish does a lot of validation, you may want to customise this.

Let's create our folder structure inside extension folder first:

  • minaction
    • settings
    • actions

Then let's define that this extension has actions by creating the minaction/settings/content.ini.append.php file:

<?php /* #?ini charset="utf-8"?
 *
[ActionSettings]
ExtensionDirectories[]=minaction
 
 */
?>

Also we need to create the php action handler for this extension, so we create the minaction/actions/content_actionhandler.php file:

<?php
 
function minaction_ContentActionHandler(&$module, &$http,
        &$objectID ) {
 
    if ($http->hasPostVariable("hello" ) ) {
        echo $http->postVariable("hello");
        eZExecution::cleanExit();
 
    }
    return;
}
?>
 

In administrator user interface, click 'setup' tab->'extensions' menu, select 'minaction', click button 'Apply Changes', click button 'Regenerate autoload arrays for extensions'. Clear the cache.

Finally you need to edit one template somewhere and create a form with one field named 'hello', as our extension check if the submited form has one variable named 'hello and one variable named 'ContentObjectID'':

<form action={"content/action"|ezurl} method="post">
<input name="ContentObjectID" type="hidden" value="-1" />
<input name="hello" type="submit" value="Hello Action!" />
 
</form>

Then when you submit the form, the php code of our extension will be called some time, and we will check if the submited form to the content/action view has some variables and do something.

Please note that you need to check your extension priority 'cause sometimes another extension can redirect the user before eZ execute this extension action.

Proudly Developed with from