Snippet: PHP Snippet Moving a node
This is compatible with eZ Publish 4.
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 ) )
{
eZContentObjectTreeNodeOperations::move( $node->attribute( 'node_id' ), $newParentNode->attribute( 'node_id' ) );
}
} 