eZpedia : The Free eZ Publish CMS Documentation Encyclopedia

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' ) );
    }
}

Article provided by eZpedia

All text is available under the terms of the GNU Free Documentation License

Powered by eZ Publish Community Project 4.2011

Hosted by Swiss eZ Publish partner YMC