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:

  1. can be linked on the current siteaccess
  2. can be rendered on the current siteaccess (provided there is a view to handle the rendering)
  3. 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 Netgen\IbexaSiteApi\API\LoadService
Container service ID netgen.ibexa_site_api.load_service

The purpose of LoadService is to load Site Content and Locations by their ID.

Methods

loadContent()

Load Content object by its ID.

Parameters string|int $id
Returns Content object
Example
$content = $loadService->loadContent(42);

loadContentByRemoteId()

Load Content object by its remote ID.

Parameters string $remoteId
Returns Content object
Example
$content = $loadService->loadContentByRemoteId('f2bfc25');

loadLocation()

Load Location object by its ID.

Parameters string|int $id
Returns Location object
Example
$content = $loadService->loadLocation(42);

loadLocationByRemoteId()

Load Location object by its remote ID.

Parameters string $remoteId
Returns Location object
Example
$content = $loadService->loadLocationByRemoteId('a44fd4e');

FindService

Instance of Netgen\IbexaSiteApi\API\FindService
Container service ID netgen.ibexa_site_api.find_service

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 Ibexa\Contracts\Core\Repository\Values\Content\Query $query
Returns Ibexa\Contracts\Core\Repository\Values\Content\Search\SearchResult
Example
$content = $findService->findContent($query);

findLocations()

Find Locations by the LocationQuery.

Parameters Ibexa\Contracts\Core\Repository\Values\Content\LocationQuery $query
Returns Ibexa\Contracts\Core\Repository\Values\Content\Search\SearchResult
Example
$locations = $findService->findLocations($locationQuery);

FilterService

Instance of Netgen\IbexaSiteApi\API\FilterService
Container service ID netgen.ibexa_site_api.filter_service

The purpose of the FindService 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 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 Ibexa\Contracts\Core\Repository\Values\Content\Query $query
Returns Location object
Example
$content = $filterService->filterContent($query);

filterLocations()

Filter Locations by the LocationQuery.

Parameters Ibexa\Contracts\Core\Repository\Values\Content\LocationQuery $query
Returns Ibexa\Contracts\Core\Repository\Values\Content\Search\SearchResult
Example
$content = $filterService->filterLocations($locationQuery);

RelationService

Instance of Netgen\IbexaSiteApi\API\RelationService
Container service ID netgen.ibexa_site_api.relation_service

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
  1. Netgen\IbexaSiteApi\API\Values\Content $content
  2. string $fieldDefinitionIdentifier
  3. array $contentTypeIdentifiers = []
Returns Content or null
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
  1. Netgen\IbexaSiteApi\API\Values\Content $content
  2. string $fieldDefinitionIdentifier
  3. array $contentTypeIdentifiers = []
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
  1. Netgen\IbexaSiteApi\API\Values\Content $content
  2. string $fieldDefinitionIdentifier
  3. array $contentTypeIdentifiers = []
Returns Location or null
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
  1. Netgen\IbexaSiteApi\API\Values\Content $content
  2. string $fieldDefinitionIdentifier
  3. array $contentTypeIdentifiers = []
Returns An array of Locations
Example
$contentItems = $relationService->loadFieldRelationLocations(
    $content,
    'relations',
    ['articles']
);

Settings

The purpose of Settings object is to provide read access to current configuration.

Instance of Netgen\IbexaSiteApi\API\Settings
Container service ID netgen.ibexa_site_api.settings

Properties

Property Type Description
$prioritizedLanguages string[] An array of prioritized languages of the current siteaccess
$useAlwaysAvailable bool
Whether always available Content is taken into account
when resolving translations
$rootLocationId string|int 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 Netgen\IbexaSiteApi\API\Site
Container service ID netgen.ibexa_site_api.site

Methods

Method Returns
getLoadService() LoadService
getFindService() FindService
getFilterService() FilterService
getRelationService() RelationService
getSettings() Settings

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 Netgen\Bundle\IbexaSiteApiBundle\NamedObject\Provider
Container service ID netgen.ibexa_site_api.named_object.provider

The purpose of NamedObjectProvider is to provide access to named objects.

Methods

hasContent()

Check if Content object with given name is configured.

Parameters string $name
Returns boolean
Example
$hasCertificate = $namedObjectProvider->hasContent('certificate');

getContent()

Get Content object by its name.

Parameters string $name
Returns Content object
Example
$certificate = $namedObjectProvider->getContent('certificate');

hasLocation()

Check if Location object with given name is configured.

Parameters string $name
Returns boolean
Example
$hasHomepage = $namedObjectProvider->hasLocation('homepage');

getLocation()

Get Location object by its name.

Parameters string $name
Returns Location object
Example
$homepage = $namedObjectProvider->getLocation('homepage');

hasTag()

Check if Tag object with given name is configured.

Parameters string $name
Returns boolean
Example
$hasColors = $namedObjectProvider->hasTag('colors');

getTag()

Get Tag object by its name.

Parameters string $name
Returns Tag object
Example
$colors = $namedObjectProvider->getTag('colors');