Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
use \eZ\Publish\API\Repository\Values\Content\Query;
$locationService = $this->getRepository()->getLocationService();
$searchService = $this->getRepository()->getSearchService();
$urlAliasService = $this->getRepository()->getUrlAliasService();
$typeService = $this->getRepository()->getContentTypeService();
$identifiers = array( 'folder', 'page', 'contact' );
$ids = array();
foreach ( $identifiers as $identifier )
$ids[] = $typeService->loadByIdentifier( $identifier )->id;
$root = $locationService->loadLocation( 2 );
$query = new Query();
$query->criterion = new Criterion\LogicalAND(
new Criterion\Subtree( $root->pathString ),
new Criterion\ContentTypeId( $ids ),
new Criterion\Visibility( Criterion\Visibility::VISIBLE )
$query->sortClauses = array(
new SortClause\LocationPriority( Query::SORT_DESC )
$results = $searchService->findContent( $query );
$items = array( );
foreach ( $results->searchHits as $hit )
$location = $locationService->loadLocation(
$locationUrl = $urlAliasService->reverseLookup( $location )->path;
$items[$locationUrl] = $location;
foreach ( $items as $url => $location )
echo "url: {$url} name: {$location->contentInfo->name}\n";
$items = eZContentObject::subTreeByNodeID(
'ClassFilterType' => 'include',
'ClassFilterArray' => array( 'folder', 'page', 'contact' ),
'SortBy' => array( array( 'priority', false ) )
foreach ( $items as $node )
echo "url: {$node->attribute( 'url_alias' )} name: {$node->attribute( 'name' )}\n";

This comment has been minimized.

Copy link

brucem commented Dec 17, 2012

Looking at this I think there is a place for a legacy data access layer on top of the new public API. It would decrease the verbosity of the code required to do the retrieval & aid in converting to the new platform.

e.g. Mimic the functionality of eZContentObject::subTreeByNodeID but use the new Public API to do the work.


This comment has been minimized.

Copy link

charlycoste commented Dec 21, 2012

Actually... There is much more code. But it's easier to extend and improves testability thanks to dependency injection. Here, you are building everything in the same script. But it's possible to have a set of defined queries:

$results = $searchService->findContent(  new MyArticlesQuery );


$results = $searchService->findContent(  new MyConfigurableQuery('articles') );


$results = $searchService->findContent(  new MockObjectForTestPurpose );

This was not possible with eZContentObject::subTreeByNodeID()

So... I'm still confident in this new API ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.