$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
The XSD for the internal XML representation can be found in the kernel: https://github.com/ezsystems/ezpezpublish-nextkernel/blob/master/eZ/Publish/Core/FieldType/XmlText/Input/Resources/schemas/ezxml.xsd.
We embed an image in our XML, using the
<embed> tag, providing an image Content ID as the
More input formats will be added later. The API for that is actually already available: you simply need to implement the
$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 !