Friday 19 August 2011 5:53:00 am
By : Thiago Campos Viana
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:
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':
<form action={"content/action"|ezurl} method="post"> <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.