eZ Community » Forums » Developer » Create an object and publish directly
expandshrink

Create an object and publish directly

Create an object and publish directly

Monday 17 August 2015 5:48:33 pm - 1 reply

Hi,

I would like to dynamically create an object in PHP. For that, I use the method eZContentFunctions::createAndPublishObject() and It works fine ! However the status of the object after the creation is still STATUS_DRAFT as I would like it to be directly  STATUS_PUBLISHED.

 

Do you have any solution for this ? Thanks you

Thursday 20 August 2015 2:22:14 pm

This is the code I use - for ezp4, not sure it changed for 5:

 
 
$contentObject = eZContentObject::createWithNodeAssignment( $parentNode, $classID, $language , $remoteID = false);
 
   if ( $contentObject )
   {
         $version = $contentObject->version( 1 );
         $version->setAttribute( 'status', eZContentObjectVersion::STATUS_DRAFT );
         $version->store();
 
         $contentObjectID = $contentObject->attribute( 'id' );
         $contentObjectAttributes = $version->contentObjectAttributes();
 
         //title
         $contentObjectAttributes[0]->setAttribute( 'data_text', $line[0] );
         $contentObjectAttributes[0]->store();        ....
 
          $operationResult = eZOperationHandler::execute( 'content', 'publish',  array( 'object_id' =>  $contentObjectID, 'version' => 1  ) );
   }
 
   if ($operationResult)
   {
         if ( $contentObject ) 
                  return $contentObject->attribute('main_node_id');
   }
expandshrink

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

36 542 Users on board!

Forums menu

Proudly Developed with from