Snippets for eZ publish 3: Moving a node

Policy checking

You can remove policy checking by removing the condition with $node->canMoveFrom() && $newParentNode->canMoveTo( $classID ).

Code sample

The following code is based on a part of the action view of the content module (kernel/content/action.php). The known variables are:

  • $node: the node we're trying to move
  • $newParentNode: the destination node we want to place our node under
$object =& $node->object();

$class =& $object->contentClass();
$classID = $class->attribute( 'id' );

if ( !in_array( $node->attribute( 'node_id' ), $newParentNode->pathArray() ) )
{
    if ( $node->canMoveFrom() && $newParentNode->canMoveTo( $classID ) )
    {
        include_once( 'kernel/classes/ezcontentobjecttreenodeoperations.php' );
        eZContentObjectTreeNodeOperations::move( $node->attribute( 'node_id' ), $newParentNode->attribute( 'node_id' ) );
    }
}