It's possible to Extend provided datatypes?

Author Message

Carlos Revillo

Wednesday 24 February 2010 11:45:46 am

Hi There.

We need a specific issue for our project. Functionality is almost entirely provided by ezflow with ezpagetype, but we need some specific things to be added.

So, we thought to build our customezpage datatype. But instead of copying ezpagetype and modifying the necessary we thought about extending eZPageType class.

So, we have now something like

class customEZPageType extends eZPageType
{
    const DATA_TYPE_STRING = 'customezpage';

    /**
     * Constructor
     *
     */
    function __construct()
    {
        parent::__construct( self::DATA_TYPE_STRING, "Custom Layout" );
    }
    
}

eZDataType::register( customEZPageType::DATA_TYPE_STRING, "customezpagetype" );

Seems to work, but there's a annoying thing that can be confusing to users. At datatypes combo while editing class, i have two 'Layout' entries (Layout is the common name given to this datatype, as Block XML or Boolean).

I though the reason is the way ezpagetype::__construct works. There you have

function __construct()
 {
    parent::__construct( self::DATA_TYPE_STRING, "Layout" );
 }

So, no matter what you do from extended ones, because this construct always sends to datatype 'ezpage' as data_type_string and "layout" as 'common name".

Do you think is not good option to extends a provided datatype? I think this could help us doing specificic things wihout having to copy lot of code.

Thank you!.

Carlos Revillo

Thursday 25 February 2010 2:06:36 am

With the help from Bratt at IRC channel, i think i've got a solution. instead of calling parent::__construct, i could just call eZDataType::__construct

So i have now

class customEZPageType extends eZPageType
{
    const DATA_TYPE_STRING = 'customezpage';

    /**
     * Constructor
     *
     */
    function __construct()
    {
        eZDataType::__construct( self::DATA_TYPE_STRING, "Custom Layout" );
    }
    
}

eZDataType::register( customEZPageType::DATA_TYPE_STRING, "customezpagetype" );

Best!

Nicolas Pastorino

Thursday 25 February 2010 2:34:35 am

Looks all good Carlos !

Stupid question : how did you make sure the customEZPageType isused instead of the default class ? It usually is not very easy to override a kernel's datatype.

Cheers !

--
Nicolas Pastorino
Director Community - eZ
Member of the Community Project Board

eZ Publish Community on twitter: http://twitter.com/ezcommunity

t : http://twitter.com/jeanvoye
G+ : http://plus.tl/jeanvoye

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 30 2025 00:45:07
Script start
Timing: Jan 30 2025 00:45:07
Module start 'layout'
Timing: Jan 30 2025 00:45:07
Module start 'content'
Timing: Jan 30 2025 00:45:08
Module end 'content'
Timing: Jan 30 2025 00:45:08
Script end

Main resources:

Total runtime0.6845 sec
Peak memory usage4,096.0000 KB
Database Queries57

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0048 588.2656151.2266
Module start 'layout' 0.00480.0025 739.492236.6797
Module start 'content' 0.00720.6765 776.1719481.6094
Module end 'content' 0.68370.0007 1,257.781311.8125
Script end 0.6845  1,269.5938 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00280.4160160.0002
Check MTime0.00120.1749160.0001
Mysql Total
Database connection0.00090.129210.0009
Mysqli_queries0.646294.4128570.0113
Looping result0.00040.0630550.0000
Template Total0.656996.020.3285
Template load0.00190.277620.0010
Template processing0.655095.696120.3275
Template load and register function0.00010.020010.0001
states
state_id_array0.00080.110610.0008
state_identifier_array0.00130.189920.0007
Override
Cache load0.00180.2659240.0001
Sytem overhead
Fetch class attribute can translate value0.00050.070520.0002
Fetch class attribute name0.00110.163040.0003
XML
Image XML parsing0.00070.107020.0004
class_abstraction
Instantiating content class attribute0.00000.001340.0000
General
dbfile0.00160.2280160.0001
String conversion0.00000.001240.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.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
3content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
6content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.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/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 15
 Number of unique templates used: 6

Time used to render debug report: 0.0001 secs