Forums / Developer / adding location

adding location

Author Message

SiXTy

Tuesday 01 November 2005 2:38:21 am

Hi
I'm trying to add new location for object with

$contentObject->createNodeAssignment(1382,0);

but it works for me only when adding main node.
Otherwise it adds empty location.
Can somebody gimme an advice?
Thanks,
Edge

Ɓukasz Serwatka

Tuesday 01 November 2005 11:28:51 pm

Hi,

Use eZNodeAssignment, example below


$objectID = 10;

$object =& eZContentObject::fetch( $objectID );

$nodeAssignment =& eZNodeAssignment::create( array(
'contentobject_id' => $object->attribute( 'id' ),
'contentobject_version' => $object->attribute( 'current_version' ),
'parent_node' => 123,
'is_main' => 0
)
);
$nodeAssignment->store();

This code will add new location for object 10 under object with nodeID 123.

Personal website -> http://serwatka.net
Blog (about eZ Publish) -> http://serwatka.net/blog

SiXTy

Saturday 05 November 2005 2:33:34 am

Hi
Thanks for reply, I tried your code, but everything is same...it adds empty location...
E.

SiXTy

Saturday 05 November 2005 3:28:26 am

I've fixed the problem by adding $operationResult = eZOperationHandler::execute( 'content', 'publish', array( 'object_id' => $object->attribute( 'id' ),
'version' => $object->attribute( 'current_version' ) ) );

but another problem emerged: the node was added without subnodes. Does anybody know if there's some function for adding node with its children?
Tnx
E.

Mark Marsiglio

Saturday 05 November 2005 9:31:15 am

It is normal behavior (a "feature") for the additional location of a node to not have the same children as the main location.

To get around this problem, we replace fetches for children with fetches of the children of the main node of the object.

In a tree nav, it looks like this...

 {let  nodechildren=fetch(content,list,hash(
                                   parent_node_id,$node_obj.main_node_id,
                                   sort_by,$node_obj.sort_array
))}

The only change is setting the parent node id as the parent object main node id.

It also might require a change in other templates that list children, like Folder.tpl.

http://www.thinkcreative.com
Turning Ideas Into Strategic Solutions