eZ\Publish\Core\Repository\ObjectStateService::createObjectState PHP Method

createObjectState() public method

Note: in current kernel: If it is the first state all content objects will set to this state.
public createObjectState ( eZ\Publish\API\Repository\Values\ObjectState\ObjectStateGroup $objectStateGroup, eZ\Publish\API\Repository\Values\ObjectState\ObjectStateCreateStruct $objectStateCreateStruct ) : eZ\Publish\API\Repository\Values\ObjectState\ObjectState
$objectStateGroup eZ\Publish\API\Repository\Values\ObjectState\ObjectStateGroup
$objectStateCreateStruct eZ\Publish\API\Repository\Values\ObjectState\ObjectStateCreateStruct
return eZ\Publish\API\Repository\Values\ObjectState\ObjectState
    public function createObjectState(APIObjectStateGroup $objectStateGroup, ObjectStateCreateStruct $objectStateCreateStruct)
    {
        if ($this->repository->hasAccess('state', 'administrate') !== true) {
            throw new UnauthorizedException('state', 'administrate');
        }
        $inputStruct = $this->buildCreateInputStruct($objectStateCreateStruct->identifier, $objectStateCreateStruct->defaultLanguageCode, $objectStateCreateStruct->names, $objectStateCreateStruct->descriptions);
        try {
            $this->objectStateHandler->loadByIdentifier($inputStruct->identifier, $objectStateGroup->id);
            throw new InvalidArgumentException('objectStateCreateStruct', 'Object state with provided identifier already exists in provided object state group');
        } catch (APINotFoundException $e) {
            // Do nothing
        }
        $this->repository->beginTransaction();
        try {
            $spiObjectState = $this->objectStateHandler->create($objectStateGroup->id, $inputStruct);
            if (is_int($objectStateCreateStruct->priority)) {
                $this->objectStateHandler->setPriority($spiObjectState->id, $objectStateCreateStruct->priority);
                // Reload the object state to have the updated priority,
                // considering that priorities are always incremental within a group
                $spiObjectState = $this->objectStateHandler->load($spiObjectState->id);
            }
            $this->repository->commit();
        } catch (Exception $e) {
            $this->repository->rollback();
            throw $e;
        }
        return $this->buildDomainObjectStateObject($spiObjectState);
    }