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);

Enterprise

Workflow

Getting workflow information

To get information about a specific workflow for a Content item, use WorkflowServiceInterface::loadWorkflowMetadataForContent:

1
2
3
4
$workflowMetadata = $this->workflowService->loadWorkflowMetadataForContent($content, $workflowName);
foreach ($workflowMetadata->markings as $marking) {
    $output->writeln($content->getName() . ' is in stage ' . $marking->name . ' in workflow ' . $workflowMetadata->workflow->getName());
}

Tip

marking, a term from Symfony Workflow, refers to a state in a workflow.

To get a list of all workflows that can be used for a given Content item, use WorkflowRegistry:

1
$supportedWorkflows = $this->workflowRegistry->getSupportedWorkflows($content);

Applying workflow transitions

To place a Content item in a workflow, use WorkflowService::start:

1
$this->workflowService->start($content, $workflowName);

To apply a transition to a Content item, use WorkflowService::apply. Additionally, you can check if the transition is possible for the given object using WorkflowService::can:

1
2
3
if ($this->workflowService->can($workflowMetadata, $transitionName)) {
    $this->workflowService->apply($workflowMetadata, $transitionName, 'Please review');
}

Bookmarks

BookmarkService enables you to read, add and remove bookmarks from content.

To view a list of all bookmarks, use BookmarkService::loadBookmarks:

1
2
3
4
5
6
7
$bookmarkList = $this->bookmarkService->loadBookmarks();

$output->writeln('Total bookmarks: ' . $bookmarkList->totalCount);

foreach ($bookmarkList->items as $bookmark) {
    $output->writeln($bookmark->getContentInfo()->name);
}

You can add a bookmark to a Content item by providing its Location object to the BookmarkService::createBookmark method:

1
2
3
$location = $this->locationService->loadLocation($locationId);

$this->bookmarkService->createBookmark($location);

You can remove a bookmark from a Location with BookmarkService::deleteBookmark:

1
$this->bookmarkService->deleteBookmark($location);

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