Global navigation

   Documentation Center
   eZ Studio & eZ Platform
     User Manual
     Technical Manual
   eZ Publish 4.x / legacy

eZ Publish (5.x)

eZ Publish 5.x | For eZ Platform & eZ Studio topics see Technical manual and User manual, for eZ Publish 4.x and Legacy topics see eZ Publish legacy

Versions Compared


  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Update git repo name


Code Block
$contentType = $contentTypeService->loadContentTypeByIdentifier( 'article' );
$contentCreateStruct = $contentService->newContentCreateStruct( $contentType, 'eng-GB' );

We first need to get the ContentType we want to create a Content with. To do so, we use ContentTypeService::loadContentTypeByIdentifier(), with the wanted ContentType identifier, like 'article'. We finally get a ContentTypeCreateStruct using ContentService::newContentCreateStruct(), providing the ContentType and a Locale Code (eng-GB).


Using our create struct, we can now set the values for our Content's fields, using the setField() method. For now, we will just set the title. setField() for a TextLine Field simply expects a string as input argument. More complex FieldTypes, like Author or Image, expect different input values.


In order to set a Location for our object, we must instantiate a LocationCreateStruct. This is done with LocationService::newLocationCreateStruct(), with the new Location's parent ID as an argument.


We will now see how the previously created Content can be updated. To do so, we will create a new draft for our Content, update it using a ContentUpdateStruct, and publish the updated Version.


This time, we create our image by directly providing an Image\Value object. The values are directly provided to the constructor using a hash with predetermined keys that depend on each Type. In this case: the path where the image can be found, its size, the file name, and an alternative text.

Images also implement a static fromString() method that will, given a path to an image, return an Image\Value object.



The XSD for the internal XML representation can be found in the kernel:

We embed an image in our XML, using the <embed> tag, providing an image Content ID as the object_id attribute.

titleUsing a custom format as input

More input formats will be added later. The API for that is actually already available: you simply need to implement the XmlText\Input interface. It contains one method, getInternalRepresentation(), that must return an internal XML string. Create your own bundle, add your implementation to it, and use it in your code!

Code Block
$input = new \My\XmlText\CustomInput( 'My custom format string' );
$contentCreateStruct->setField( 'body', $input );


Code Block
$contentService->delete( $contentInfo );

ContentService::delete() method expects a ContentInfo as an argument. It will delete the given Content, all of its Locations, as well as all of the Content's Locations' descendants and their associated Content. Use with caution !