eZ\Publish\Core\Repository\SectionService::assignSection PHP Method

assignSection() public method

Assigns the content to the given section this method overrides the current assigned section.
public assignSection ( eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo, eZ\Publish\API\Repository\Values\Content\Section $section )
$contentInfo eZ\Publish\API\Repository\Values\Content\ContentInfo
$section eZ\Publish\API\Repository\Values\Content\Section
    public function assignSection(ContentInfo $contentInfo, Section $section)
    {
        $loadedContentInfo = $this->repository->getContentService()->loadContentInfo($contentInfo->id);
        $loadedSection = $this->loadSection($section->id);
        if ($this->repository->canUser('section', 'assign', $loadedContentInfo, $loadedSection) !== true) {
            throw new UnauthorizedException('section', 'assign', array('name' => $loadedSection->name, 'content-name' => $loadedContentInfo->name));
        }
        $this->repository->beginTransaction();
        try {
            $this->sectionHandler->assign($loadedSection->id, $loadedContentInfo->id);
            $this->repository->commit();
        } catch (Exception $e) {
            $this->repository->rollback();
            throw $e;
        }
    }