Forums / Developer / It's possible to Extend provided datatypes?

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