Skip to content

URLService

URLService enables you to find, load and update external URLs used in RichText and URL Fields.

To view a list of all URLs, use URLService::findUrls

URLService::findUrls takes as argument a URLQuery, in which you need to specify:

  • query filter e.g. Section
  • Sort Clauses for URL queries
  • offset for search hits, used for paging the results
  • query limit. If value is 0, search query will not return any search hits
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
use eZ\Publish\API\Repository\Values\URL\URLQuery;
use eZ\Publish\API\Repository\Values\URL\Query\Criterion;
use eZ\Publish\API\Repository\Values\URL\Query\SortClause; 

# ...

$urlQuery = new URLQuery();
$urlQuery->filter = new Criterion\LogicalAnd(
    [
    new Criterion\SectionIdentifier(['standard']),
    new Criterion\Validity(true),
    ]
);
$urlQuery->sortClauses = [
    new SortClause\URL(SortClause::SORT_DESC)
];
$urlQuery->offset = 0;
$urlQuery->limit = 25;

$results = $urlService->findUrls($urlQuery);

URL criteria reference

URL criteria URL based on
LogicalAnd Implements a logical AND Criterion. It matches if ALL of the provided Criteria match.
LogicalNot Implements a logical NOT Criterion. It matches if the provided Criterion doesn't match.
LogicalOr Implements a logical OR Criterion. It matches if at least one of the provided Criteria match.
MatchAll Returns all URL results.
MatchNone Returns no URL results.
Pattern Matches URLs that contain a pattern.
SectionId Matches URLs from content placed in the Section with the specified ID.
SectionIdentifier Matches URLs from content placed in Sections with the specified identifiers.
Validity Matches URLs based on validity flag.
VisibleOnly Matches URLs from published content.

URL Sort Clauses reference

Sort Clauses are the sorting options for URLs.

All Sort Clauses can take the following optional argument:

  • sortDirection - the direction of the sorting, either \eZ\Publish\API\Repository\Values\URL\Query\SortClause::SORT_ASC (default) or \eZ\Publish\API\Repository\Values\URL\Query\SortClause::SORT_DESC

Sort Clauses

Sort Clause Sorting based on
Id URL ID
URL URL address