Global navigation

   Documentation Center
   eZ Studio & eZ Platform
     User Manual
     Technical Manual
     Glossary
   eZ Publish 4.x / legacy

 
eZ Publish (5.x)

eZ Publish 5.x | For eZ Platform & eZ Studio topics see Technical manual and User manual, for eZ Publish 4.x and Legacy topics see eZ Publish legacy

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

ContentService::delete(ContentInfo $contentInfo)

 

Receipt 17 - Assinging section to content

On creation of content  the section of the parent location's content is assigned by default to the new content. However it is possible to assign a specific section on creation by setting it in the ContentCreateStruct (Receipt 5):

$contentCreateStruct->section = $sectionId

Later on sections can be assigned with the following code:

Code Block
languagephp
titleassign section to content
        // get the content service from the repository
        $contentService = $repository->getContentService();
        // get the section service from the repsitory
        $sectionService = $repository->getSectionService();
        // get the user service from the repsitory
        try
        {
            // load the content info from the given content id
            $contentInfo = $contentService->loadContentInfo($contentId);
            // load the section
            $section = $sectionService->loadSection($sectionId);
            // assign the section to the content
            $sectionService->assignSection($contentInfo, $section);
            // realod an print out
            $contentInfo =  $contentService->loadContentInfo($contentId);
            // should show the new section id
            $output->writeln($contentInfo->sectionId);
        }
        catch(\eZ\Publish\API\Repository\Exceptions\NotFoundException $e)
        {
            // react on content or section not found
            $output->writeln($e->getMessage());
        }
        catch(\eZ\Publish\API\Repository\Exceptions\UnauthorizedException $e)
        {
            // react on permission denied
            $output->writeln($e->getMessage());
        }