Forums / Developer / Need help to complete a custom datatype

Need help to complete a custom datatype

Author Message

Sébastien Antoniotti

Saturday 24 May 2008 10:11:18 am

Hi,

I'm using a custom datatype who stores a birthday date as a data_text (1925-12-20 by ex.).

I'm not the author of this datatype, and I encouter a problem when I try to create instances of the class who uses this datatype from PHP.

The problem is simply that the datatype is empty although the object is correctly created.

To create the object from PHP, I use the eZContentFunctions::createAndPublishObject method, and I set my attribute content like this :

$attributes_content = array(
...
'birthday' 	=> "1925-12-20",
...
);

I have searched into the forum, and I seen that the datatype must implement the storeObjectAttribute method, and my datatype doesn't.

The problem is that into the storeObjectAttribute method, I don't know how to retrieve the value passed to eZContentFunctions::createAndPublishObject...

I'm very lost because this is the first time I work with custom datatypes !

Thanks in advance !

eZ Publish Freelance
web : http://www.webaxis.fr

Kristof Coomans

Saturday 24 May 2008 10:30:21 am

Hi Sébastien

eZContentFunctions::createAndPublishObject() makes use of the fromString() method of the datatype. For a very simple example, see function fromString in kernel/classes/datatypes/ezstring/ezstringtype.php. Good luck! And don't forget to share your enhancement to this datatype ;)

independent eZ Publish developer and service provider | http://blog.coomanskristof.be | http://ezpedia.org

Sébastien Antoniotti

Saturday 24 May 2008 11:36:33 am

Hi Kristof,

You put me on the right way !

So here are the two methods I added to this datatype to make it compatible with eZContentFunctions::createAndPublishObject :

function storeObjectAttribute( $contentObjectAttribute )
{
	$data = $contentObjectAttribute->content();
	$data = sprintf('%04d-%02d-%02d', $data['year'], $data['month'], $data['day']) ;
	$contentObjectAttribute->setAttribute( "data_text", $data );
	return false;
}

function fromString( $contentObjectAttribute, $string )
{
	return $contentObjectAttribute->setAttribute( 'data_text', $string );
}

Many thanks !

eZ Publish Freelance
web : http://www.webaxis.fr