Table of contents:
The following code will create a new content object and an initial draft version. It is based on a part of the action view of the content module (kernel/content/action.php).
$class = eZContentClass::fetchByIdentifier( $contentClassIdentifier ); if ( is_object( $class ) ) { $contentClassID = $class->attribute( 'id' ); $parentContentObject =& $node->attribute( 'object' ); $accessResult = $parentContentObject->checkAccess( 'create', $contentClassID, $parentContentObject->attribute( 'contentclass_id' ) ); if ( $accessResult == '1' ) { include_once( 'kernel/classes/datatypes/ezuser/ezuser.php' ); $user =& eZUser::currentUser(); $userID =& $user->attribute( 'contentobject_id' ); $sectionID = $parentContentObject->attribute( 'section_id' ); include_once( 'lib/ezdb/classes/ezdb.php' ); $db =& eZDB::instance(); $db->begin(); $contentObject =& $class->instantiate( $userID, $sectionID ); $nodeAssignment = eZNodeAssignment::create( array( 'contentobject_id' => $contentObject->attribute( 'id' ), 'contentobject_version' => $contentObject->attribute( 'current_version' ), 'parent_node' => $node->attribute( 'node_id' ), 'is_main' => 1 ) ); $nodeAssignment->store(); $db->commit(); } }
Now that you have created a new content object, you will probably want to fill it's attributes with data and publish it.
This feature is available since eZ publish 3.9.
From eZ Publish 3.9 on, there's also the static method eZContentFunctions::createAndPublishObject() which handles object creation, filling attributes and publishing at one location. The filling of the attributes is handled by the fromString functions implemented by the datatypes. For more information on this, see the fromString and toString feature doc.
If you want to bypass the policy system, then remove the conditional check on $accessResult.
All text is available under the terms of the GNU Free Documentation License
Powered by eZ Publish 4.0.3
Hosting by Swiss eZ Publish partner YMC