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->permissionResolver->canUser('section', 'edit', $sectionCreateStruct)) {
            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);
    }
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->permissionResolver->canUser('section', 'edit', $sectionCreateStruct)) {
            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);
    }
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 -> permissionResolver -> canUser ( 'section' , 'edit' , $ sectionCreateStruct ) ) { 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 ) ; }
Creates a new Section in the content repository.

@throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException If the current user user is not allowed to create a section
@throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException If the new identifier in $sectionCreateStruct already exists

@param \eZ\Publish\API\Repository\Values\Content\SectionCreateStruct $sectionCreateStruct

@return \eZ\Publish\API\Repository\Values\Content\Section The newly created section
Creates a new Section in the content repository .