This site has been archived and you can no longer log in or post new messages. For up-to-date community resources please visit ezplatform.com

eZ Community » Forums » Developer » It's possible to Extend provided...
expandshrink

It's possible to Extend provided datatypes?

It's possible to Extend provided datatypes?

Wednesday 24 February 2010 8:45:46 pm - 2 replies

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

Thursday 25 February 2010 11: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!

Modified on Thursday 25 February 2010 11:07:25 am by Carlos Revillo

Thursday 25 February 2010 11: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 !

expandshrink

You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu

Proudly Developed with from