Services
First thing to know about the Site API services is that all of them handle language configuration in a completely transparent way. You can be sure that all objects you work with:
can be linked on the current siteaccess
can be rendered on the current siteaccess (provided there is a view to handle the rendering)
are loaded in the single correct translation to be rendered on the current siteaccess
Caution
The above is affected by Cross-siteaccess content feature, read the documentation there for more information on how and when that is the case.
This works for both Content and Locations, whether they are obtained through search, loading by the ID, as relations or otherwise. If the object doesn’t have a translation that can be rendered on a siteaccess, you won’t be able to load it in the first place. That means you can put the whole language logic off your mind and solve real problems instead.
Following services are available:
LoadService
Instance of |
|
Container service ID |
|
The purpose of LoadService is to load Site Content and Locations by their ID.
Methods
loadContent()
Load Content object by its ID.
Parameters |
|
Returns |
|
Example |
$content = $loadService->loadContent(42);
|
loadContentByRemoteId()
Load Content object by its remote ID.
Parameters |
|
Returns |
|
Example |
$content = $loadService->loadContentByRemoteId('f2bfc25');
|
loadLocation()
Load Location object by its ID.
Parameters |
|
Returns |
|
Example |
$content = $loadService->loadLocation(42);
|
loadLocationByRemoteId()
Load Location object by its remote ID.
Parameters |
|
Returns |
|
Example |
$content = $loadService->loadLocationByRemoteId('a44fd4e');
|
FindService
Instance of |
|
Container service ID |
|
The purpose of the FindService is to find Content and Locations by using Ibexa CMS
Repository Search API. This service will use the search engine that is configured for the
Repository. That can be Legacy search engine or Solr search engine.
The service will return SearchResult object from the Repository API containing Site API objects.
Methods
findContent()
Find Content by the Content Query.
Parameters |
|
Returns |
|
Example |
$content = $findService->findContent($query);
|
findLocations()
Find Locations by the LocationQuery.
Parameters |
|
Returns |
|
Example |
$locations = $findService->findLocations($locationQuery);
|
FilterService
Instance of |
|
Container service ID |
|
The purpose of the FilterService is to find Content and Locations by using Ibexa CMS
Repository Search API. That is the same as FindService, but with the difference that it will
always use Legacy search engine.
While Solr search engine provides more features and more performance than Legacy search engine, it’s a separate system that needs to be synchronized with changes in the database. This synchronization comes with a delay, which can be a problem in some cases.
FilterService gives you access to search that is always up to date, because it uses Legacy search
engine that works directly with database. At the same time, search on top of Solr, with all the
advanced features (like fulltext search or facets) is still available through FindService.
The service will return SearchResult object from the Repository API containing Site API objects.
Methods
filterContent()
Filter Content by the Content Query.
Parameters |
|
Returns |
|
Example |
$content = $filterService->filterContent($query);
|
filterLocations()
Filter Locations by the LocationQuery.
Parameters |
|
Returns |
|
Example |
$content = $filterService->filterLocations($locationQuery);
|
RelationService
Instance of |
|
Container service ID |
|
The purpose of RelationService is to provide a way to load field relations. This needs to be
done respecting permissions and sort order and actually requires surprising amount of code when
using Repository API.
Methods
loadFieldRelation()
Get single field relation Content from a specific field of a given Content.
The method will return null if the field does not contain relations that can be loaded by the
current user. If the field contains multiple relations, the first one will be returned. The method
supports optional filtering by ContentType.
Parameters |
|
Returns |
Content or |
Example |
$content = $relationService->loadFieldRelation(
$content,
'relations',
['articles']
);
|
loadFieldRelations()
Get all field relation Content items from a specific field of a given Content. The method supports optional filtering by ContentType.
Parameters |
|
Returns |
An array of Content items |
Example |
$contentItems = $relationService->loadFieldRelations(
$content,
'relations',
['articles']
);
|
loadFieldRelationLocation()
Get single field relation Location from a specific field of a given Content.
The method will return null if the field does not contain relations that can be loaded by the
current user. If the field contains multiple relations, the first one will be returned. The method
supports optional filtering by ContentType.
Parameters |
|
Returns |
Location or |
Example |
$content = $relationService->loadFieldRelationLocation(
$content,
'relations',
['articles']
);
|
loadFieldRelationLocations()
Get all field relation Locations from a specific field of a given Content. The method supports optional filtering by ContentType.
Parameters |
|
Returns |
An array of Locations |
Example |
$contentItems = $relationService->loadFieldRelationLocations(
$content,
'relations',
['articles']
);
|
loadReverseFieldRelations()
Get all reverse relation Content items from a specific field to a given Content. The method supports optional filtering by ContentType.
Parameters |
|
Returns |
An array of Content items |
Example |
$contentItems = $relationService->loadReverseFieldRelations(
$content,
'relations',
['articles']
);
|
loadReverseFieldRelationLocations()
Get all reverse relation Locations from a specific field to a given Content. The method supports optional filtering by ContentType.
Parameters |
|
Returns |
An array of Locations |
Example |
$contentItems = $relationService->loadReverseFieldRelationLocations(
$content,
'relations',
['articles']
);
|
Settings
The purpose of Settings object is to provide read access to current configuration.
Instance of |
|
Container service ID |
|
Properties
Property |
Type |
Description |
|---|---|---|
|
|
An array of prioritized languages of the current siteaccess |
|
|
Whether always available Content is taken into account
when resolving translations
|
|
|
Root Location of the current siteaccess |
Site
The purpose of Site service is to aggregate all other Site API services in one place. It
implements a getter method for each of the services described above.
Instance of |
|
Container service ID |
|
Methods
Method |
Returns |
|---|---|
|
|
|
|
|
|
|
|
|
NamedObjectProvider
The purpose of NamedObjectProvider service is to provide access to named objects. Configuration
of named objects is documented on the Configuration page.
Instance of |
|
Container service ID |
|
The purpose of NamedObjectProvider is to provide access to named objects.
Methods
hasContent()
Check if Content object with given name is configured.
Parameters |
|
Returns |
|
Example |
$hasCertificate = $namedObjectProvider->hasContent('certificate');
|
getContent()
Get Content object by its name.
Parameters |
|
Returns |
|
Example |
$certificate = $namedObjectProvider->getContent('certificate');
|
hasLocation()
Check if Location object with given name is configured.
Parameters |
|
Returns |
|
Example |
$hasHomepage = $namedObjectProvider->hasLocation('homepage');
|
getLocation()
Get Location object by its name.
Parameters |
|
Returns |
|
Example |
$homepage = $namedObjectProvider->getLocation('homepage');
|
hasTag()
Check if Tag object with given name is configured.
Parameters |
|
Returns |
|
Example |
$hasColors = $namedObjectProvider->hasTag('colors');
|
getTag()
Get Tag object by its name.
Parameters |
|
Returns |
Tag object |
Example |
$colors = $namedObjectProvider->getTag('colors');
|