use eZ\Publish\API\Repository\Values\Content\ContentCreateStruct; use eZ\Publish\API\Repository\Values\Content\ContentUpdateStruct; use eZ\Publish\Core\Persistence\Legacy\Content\FieldValue\ConverterRegistry; use eZ\Publish\Core\Persistence\Legacy\Content\FieldValue\Gateway; $createStruct = new ContentCreateStruct(); $createStruct->setContentType(new ContentType(1)); // set content type ID $createStruct->setField('title', 'Hello World'); // set title field value $createStruct->setField('body', 'This is my first content object!'); // set body field value $contentService = $container->get('ezpublish.api.repository')->getContentService(); $content = $contentService->createContent($createStruct);
use eZ\Publish\API\Repository\Values\Content\Content; use eZ\Publish\API\Repository\Values\Content\ContentUpdateStruct; use eZ\Publish\Core\Persistence\Legacy\Content\FieldValue\Gateway; $contentService = $container->get('ezpublish.api.repository')->getContentService(); $content = $contentService->loadContent(1); $updateStruct = new ContentUpdateStruct($content); $updateStruct->setField('title', 'New Title'); $updateStruct->setField('body', 'Updated body'); $contentService->updateContent($content->versionInfo, $updateStruct);In this example, we load an existing content object with ID 1 and update its title and body field values. Package library: eZ/Publish/SDK.