Skip to content

Managing the Repository

Sections

Sections enable you to divide content into groups which can later be used e.g. as basis for permissions.

Creating Sections

To create a new Section, you need to make use of the SectionCreateStruct and pass it to the SectionService::createSection method:

1
2
3
4
$sectionCreateStruct = $this->sectionService->newSectionCreateStruct();
$sectionCreateStruct->name = 'New section';
$sectionCreateStruct->identifier = 'newsection';
$this->sectionService->createSection($sectionCreateStruct);

Getting Section information

You can use SectionService to retrieve Section information such as whether it is in use:

1
$output->writeln(($this->sectionService->isSectionUsed($section) ? 'This section is in use.' : 'This section is not in use.'));

Listing content in a Section

To list Content items assigned to a Section you need to make a query for Content belonging to this section, by applying the SearchService. You can also use the query to get the total number of assigned Content items:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
$query = new LocationQuery();
$query->filter = new Criterion\SectionId([
    $section->id,
]);

$result = $this->searchService->findContentInfo($query);
$output->writeln('Number of Content items in this section: ' . $result->totalCount);

foreach ($result->searchHits as $seachResult) {
    $output->writeln($seachResult->valueObject->name);
}

Assigning Section to content

To assign content to a Section, use the SectionService::assignSection method. You need to provide it with the ContentInfo object of the Content item, and the Section object:

1
2
3
$contentInfo = $this->contentService->loadContentInfo($contentId);
$section = $this->sectionService->loadSectionByIdentifier($sectionIdentifier);
$this->sectionService->assignSection($contentInfo, $section);

Note that assigning a Section to content does not automatically assign it to the Content item's children.

Object states

Object states enable you to set a custom state to any content. States are grouped into Object state groups.

Creating Object states

To create an Object state group and add Object states to it, you need to make use of the ObjectStateService:

1
2
3
4
$objectStateGroupStruct = $this->objectStateService->newObjectStateGroupCreateStruct('rank');
$objectStateGroupStruct->defaultLanguageCode = 'eng-GB';
$objectStateGroupStruct->names = ['eng-GB' => 'rank'];
$this->objectStateService->createObjectStateGroup($objectStateGroupStruct);

ObjectStateService::createObjectStateGroup takes as argument an ObjectStateGroupCreateStruct, in which you need to specify the identifier, default language and at least one name for the group.

To create an Object state inside a group, use ObjectStateService::newObjectStateCreateStruct and provide it with an ObjectStateCreateStruct:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
$objectStateGroup = $this->objectStateService->loadObjectStateGroup($objectStateGroupId);

$stateRegularStruct = $this->objectStateService->newObjectStateCreateStruct('regular');
$stateRegularStruct->defaultLanguageCode = 'eng-GB';
$stateRegularStruct->names = ['eng-GB' => 'regular'];
$this->objectStateService->createObjectState($objectStateGroup, $stateRegularStruct);

$stateSpecialStruct = $this->objectStateService->newObjectStateCreateStruct('special');
$stateSpecialStruct->defaultLanguageCode = 'eng-GB';
$stateSpecialStruct->names = ['eng-GB' => 'special'];
$this->objectStateService->createObjectState($objectStateGroup, $stateSpecialStruct);

Assigning Object state

To assign an Object state to a Content item, use ObjectStateService::setContentState. Provide it with a ContentInfo object of the Content item, the Object state group and the Object state:

1
2
3
4
5
$contentInfo = $this->contentService->loadContentInfo($contentId);
$objectStateGroup = $this->objectStateService->loadObjectStateGroup($objectStateGroupId);
$objectState = $this->objectStateService->loadObjectState($objectStateId);

$this->objectStateService->setContentState($contentInfo, $objectStateGroup, $objectState);

Languages

Getting Language information

To get a list of all Languages in the system use LanguageService::loadLanguages:

1
2
3
4
5
$languageList = $this->languageService->loadLanguages();

foreach ($languageList as $language) {
    $output->writeln($language->languageCode . ': ' . $language->name);
}

Creating a Language

To create a new language, you need to create a LanguageCreateStruct and provide it with the language code and language name. Then, use LanguageService::createLanguage and pass the LanguageCreateStruct to it:

1
2
3
4
$languageCreateStruct = $this->languageService->newLanguageCreateStruct();
$languageCreateStruct->languageCode = 'ger-DE';
$languageCreateStruct->name = 'German';
$this->languageService->createLanguage($languageCreateStruct);
Read the Docs