eZ Community » Forums » eZ Publish 5 Platform » CookBook Bundle : API eZ 5 create...

CookBook Bundle : API eZ 5 create class and attributes

CookBook Bundle : API eZ 5 create class and attributes

Wednesday 15 April 2015 9:51:56 am - 8 replies

Hi there,

In the cookbook at this url : https://github.com/ezsystems/CookbookBundle/blob/master/Command/CreateContentTypeCommand.php#L70

there is a command to create a content type with ezstring attributes. It's working fine if there is only those attributes but what about other attributes ? ezobjectrelationlist, ezinteger, ezxmltext for example. They need other info like "preferred_number_of_rows", "selection_method", "allowed_classes".

How can i create such a type with all attributes using the eZ 5 API ?

Thanks for your help.



Modified on Wednesday 15 April 2015 9:54:55 am by Task Mikaël

Wednesday 15 April 2015 10:23:31 am

Hi Mikaël,

we don't have ready to go examples for all field types, but you can check the documentation and field type integration tests to see how it should be used.

For example, in RelationList case (ezobjectrelationlist):

Not strictly needed, but familiarizing with field type implementation will definitely help you. Also check out the Field Type API and best practices doc page:

Hope this helps.



Wednesday 15 April 2015 11:56:02 am


So you say it's not possible "for now" to create all field type with a command ? (or i didn't understand)

I'll look at the links. Thanks for the fast answer.

Wednesday 15 April 2015 2:23:11 pm

Hi again,

no, it is possible, but we don't have the code examples for every single field type, aside from what is available in the integration tests.

For example, in the integration test for RelationList field type, you can easily see what are valid/invalid field settings, validator configurations and values. In documentation these are explained in more detail, both in general and specifically for each field type.


Wednesday 15 April 2015 5:38:50 pm


Ok, it is working. thanks.

Marking the topic as solved.

Thursday 16 April 2015 1:46:26 pm


I am reopening the topic because i have problem setting :

- $fieldCreateStruct->fieldSettings
- $fieldCreateStruct->validatorConfiguration

in the script. I've read in the links you gave me that in order to set $fieldCreateStruct->fieldSettings you have to pass an array like this :

$settings = array("selectionMethod" => Type::SELECTION_BROWSE,"selectionRoot" => null,"selectionContentTypes" => array());

so my script is :



but it is returning : "ContentType FieldDefinitions did not validate".

I may appear foolish asking this but am I setting the $fieldCreateStruct->fieldSettings and $fieldCreateStruct->validatorConfiguration correclty ?


Modified on Thursday 16 April 2015 1:49:43 pm by Task Mikaël

Thursday 16 April 2015 3:42:34 pm

Asking the question is often asking the answer happy.gif Emoticon the array i was passing was not formatted correctly for certain attributes i was creating.

I have found the solution following the Tests classes.

Topic closed.

Modified on Thursday 16 April 2015 3:43:23 pm by Task Mikaël

Monday 20 April 2015 12:41:41 pm

Good news that you got this solved.

Where would you expect to find this info, Mikaël ? In the Cookbook's code, or in the tutorial itself ? We can't really cover all the use-cases here, so I guess we should add links to the FieldTypes references as examples, and maybe show an example for a more complex one.

Any suggestion ?

Monday 20 April 2015 2:28:52 pm


I'd say in the CookBook, if you expect to keep and upgrade the CookBook, i would definitely look there. The examples already present helped very much. Espacially in my case, because i'm only using commands to manage the content of my database. Each project has its particularities but it is a good basis to start.



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

36 542 Users on board!

Forums menu

Proudly Developed with from