This site has been archived and you can no longer log in or post new messages. For up-to-date community resources please visit

eZ Community » Forums » eZ Publish 5 Platform » Using Public API

Using Public API

Using Public API

Wednesday 01 October 2014 7:00:49 pm - 5 replies

Hi Guys,

i am trying to create an article with the new public api. I am using ezPublish Community 2014.3 for local development but i am aiming to use the enterprise edition (5.2) later.

Currently i am stuck on creating an article from some strings. 

I am using this documentation:

So i setting the values of my $contentCreateStruct like this: 

$contentCreateStruct->setField('title', "TITLE" ) ;           

$contentCreateStruct->setField('intro', "INTROTEXT" ) ;           

$contentCreateStruct->setField('body', "MAINTEXT " ) ;

As soon as i try to create a draft form my $contentCreateStruct with $draft = $contentService->createContent( $contentCreateStruct, array( $locationCreateStruct ) ) ;

I get this error (code is running in a worker command):                                                                                                        


  Argument 'xmlString' is invalid: Validation of XML content failed: Start tag expected, '<' not found  

  The document has no document element.                                                                 

If i understand the documentation right, xml should not be needed for field values, but it seems like it is.

Do you have any hints for helping me out with this issue?


Best regards,



In admin->setup->Classes->Content->article i can see, that intro and bodytext have the prefix [XML BLOCK], so i think this causes my problems.


It seems like i have to parse my string with the ezSimplifiedXMLInputParser. I will try that now.

Modified on Thursday 02 October 2014 9:32:01 am by Jacob Ester

Thursday 02 October 2014 10:27:07 am

Hi Jacob

Yes, you will need to use eZXML formatted text. You'll find documentation and cookbook on public API in the documentation center. See also FieldTypes reference where you can find XmlText.

As for the Enterprise version, 5.2 is not the best choice as support will end at the end of this year. You should consider at least 5.3 or upcoming 5.4.

Thursday 02 October 2014 1:32:36 pm

Hi Jérôme,

thank you for your answer. 

I am working with the cookbook and the other tutorials inside the documentation center. We are already planning the update to 5.3.

So what i have done since yesterday is trying to get the ezSimplifiedXMLInputParser:

$teaser = $this->teaser;           

$xmlTeaser = $legacykernel->runCallback(               

function () use ($teaser) {

                    $parser = new \ezSimplifiedXMLInputParser();                   


                    $xmlDocument = $parser->process($teaser);                   

                    return eZXMLTextType::domString($xmlDocument);              




But all i've got is something like:

PHP Fatal error:  Call to undefined method Closure::runCallback() in .../bla.php. If i am dumping my $legacykernel it seems like its filled fine with $legacykernel = $this->getContainer()->get( 'ezpublish_legacy.kernel' );


Any hints?

Best regards,


Thursday 02 October 2014 2:26:41 pm


ezpublish_legacy.kernel is actually a closure, so you first need to run it to get the actual object:

$legacyKernelClosure = $this->get( 'ezpublish_legacy.kernel' );
$legacyKernel = $legacyKernelClosure();
$xmlTeaser = $legacyKernel->runCallback(
    function ()
        // ...

If you're inside a controller extending eZ\Bundle\EzPublishCoreBundle\Controller, you can get the legacy kernel object directly by doing $this->getLegacyKernel().

Monday 06 October 2014 5:57:42 pm

That really helped me. Thank you Jérôme.

Tuesday 07 October 2014 4:49:12 pm

A few more questions while using the Public PHP Api.

Best way how to create a gallery with images.

For the moment i creating the gallery object first and publish it for getting the content node id/mainLocationId. With this ID i create the images as childs of the previously published gallery. Do i have to use some state like (published/offline) which is only visible with the admin siteacces for getting the mainLocationId or are there better practices to create a gallery with some images as childnodes? Because getting the mainLocationId of the draft is not possible (although the draft has an NodeId/MainLocationId in the Admin Backend).

Thank you guys for your help

Modified on Tuesday 07 October 2014 5:02:41 pm by Jacob Ester


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

36 542 Users on board!

Forums menu

Proudly Developed with from