Tip: The minimum content action extension

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:

  • 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':

<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.

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.

eZ debug

Timing: Jan 17 2025 23:51:01
Script start
Timing: Jan 17 2025 23:51:01
Module start 'layout'
Timing: Jan 17 2025 23:51:01
Module start 'content'
Timing: Jan 17 2025 23:51:01
Module end 'content'
Timing: Jan 17 2025 23:51:01
Script end

Main resources:

Total runtime0.0852 sec
Peak memory usage6,144.0000 KB
Database Queries43

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0059 588.0547152.6406
Module start 'layout' 0.00590.0027 740.695339.5000
Module start 'content' 0.00860.0747 780.1953361.1328
Module end 'content' 0.08330.0018 1,141.328115.7031
Script end 0.0851  1,157.0313 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00333.8608150.0002
Check MTime0.00121.4217150.0001
Mysql Total
Database connection0.00070.866310.0007
Mysqli_queries0.035842.0793430.0008
Looping result0.00030.3863410.0000
Template Total0.050959.820.0255
Template load0.00242.820120.0012
Template processing0.048556.939920.0242
Template load and register function0.00010.119510.0001
states
state_id_array0.00080.993410.0008
state_identifier_array0.00111.271620.0005
Override
Cache load0.00202.2900220.0001
Sytem overhead
Fetch class attribute name0.00202.373730.0007
class_abstraction
Instantiating content class attribute0.00000.008430.0000
General
dbfile0.00080.8854100.0001
String conversion0.00000.009240.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplblog_entry/full.tplextension/community_design/design/suncana/override/templates/blog_entry/full.tplEdit templateOverride template
2content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
1content/datatype/view/ezxmltags/link.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/link.tplEdit templateOverride template
6content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
2content/datatype/view/ezxmltags/li.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/li.tplEdit templateOverride template
2content/datatype/view/ezxmltags/ul.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/ul.tplEdit templateOverride template
3content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
1content/datatype/view/ezkeyword.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezkeyword.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 19
 Number of unique templates used: 9

Time used to render debug report: 0.0001 secs