Global navigation

   Documentation Center
   eZ Studio & eZ Platform
     User Manual
     Technical Manual
     Glossary
   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

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Fixed links, making them to point to apidoc.ez.no

...

Code Block
languagephp
$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.

Note

The ContentCreateStruct::setField() method can take several type of arguments.

In any case, whatever the FieldType is, a Value of this type can be provided. For instance, a TextLine\Value can be provided for a TextLine\Type. Depending on the FieldType implementation itself, more specifically on the fromHash() method every FieldType implements, various arrays can be accepted, as well as primitive types, depending on the Type.

...

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.

...

Note
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
languagephp
$input = new \My\XmlText\CustomInput( 'My custom format string' );
$contentCreateStruct->setField( 'body', $input );

...

Code Block
languagephp
$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 !

...