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

createSection() public method

Creates a new Section in the content repository.
public createSection ( eZ\Publish\API\Repository\Values\Content\SectionCreateStruct $sectionCreateStruct ) : eZ\Publish\API\Repository\Values\Content\Section
$sectionCreateStruct eZ\Publish\API\Repository\Values\Content\SectionCreateStruct
return eZ\Publish\API\Repository\Values\Content\Section The newly created section
    public function createSection(SectionCreateStruct $sectionCreateStruct)
    {
        if (!is_string($sectionCreateStruct->name) || empty($sectionCreateStruct->name)) {
            throw new InvalidArgumentValue('name', $sectionCreateStruct->name, 'SectionCreateStruct');
        }
        if (!is_string($sectionCreateStruct->identifier) || empty($sectionCreateStruct->identifier)) {
            throw new InvalidArgumentValue('identifier', $sectionCreateStruct->identifier, 'SectionCreateStruct');
        }
        if ($this->repository->hasAccess('section', 'edit') !== true) {
            throw new UnauthorizedException('section', 'edit');
        }
        try {
            $existingSection = $this->loadSectionByIdentifier($sectionCreateStruct->identifier);
            if ($existingSection !== null) {
                throw new InvalidArgumentException('sectionCreateStruct', 'section with specified identifier already exists');
            }
        } catch (APINotFoundException $e) {
            // Do nothing
        }
        $this->repository->beginTransaction();
        try {
            $spiSection = $this->sectionHandler->create($sectionCreateStruct->name, $sectionCreateStruct->identifier);
            $this->repository->commit();
        } catch (Exception $e) {
            $this->repository->rollback();
            throw $e;
        }
        return $this->buildDomainSectionObject($spiSection);
    }