eZ\Publish\Core\Repository\Tests\Service\Integration\ContentTypeBase::createContentType PHP Метод

createContentType() защищенный Метод

Creates a ContentType with identifier "new-type" and remoteId "new-remoteid".
protected createContentType ( boolean $publish = true, integer $creatorId = null ) : eZ\Publish\API\Repository\Values\ContentType\ContentType | eZ\Publish\API\Repository\Values\ContentType\ContentTypeDraft
$publish boolean
$creatorId integer
Результат eZ\Publish\API\Repository\Values\ContentType\ContentType | eZ\Publish\API\Repository\Values\ContentType\ContentTypeDraft
    protected function createContentType($publish = true, $creatorId = null)
    {
        $contentTypeService = $this->repository->getContentTypeService();
        if (!isset($creatorId)) {
            $creatorId = $this->repository->getCurrentUserReference()->getUserId();
        }
        $typeCreateStruct = $contentTypeService->newContentTypeCreateStruct('new-type');
        $typeCreateStruct->names = array('eng-US' => 'American type title', 'eng-GB' => 'British type title');
        $typeCreateStruct->descriptions = array('eng-US' => 'American type description', 'eng-GB' => 'British type description');
        $typeCreateStruct->remoteId = 'new-remoteid';
        $typeCreateStruct->creatorId = $creatorId;
        $typeCreateStruct->creationDate = new \DateTime();
        $typeCreateStruct->mainLanguageCode = 'eng-GB';
        $typeCreateStruct->nameSchema = '<title>';
        $typeCreateStruct->urlAliasSchema = '<title>';
        $titleFieldCreate = $contentTypeService->newFieldDefinitionCreateStruct('title', 'ezstring');
        $titleFieldCreate->names = array('eng-US' => 'American title field name', 'eng-GB' => 'British title field name');
        $titleFieldCreate->descriptions = array('eng-US' => 'American title field description', 'eng-GB' => 'British title field description');
        $titleFieldCreate->fieldGroup = 'blog-content';
        $titleFieldCreate->position = 1;
        $titleFieldCreate->isTranslatable = true;
        $titleFieldCreate->isRequired = true;
        $titleFieldCreate->isInfoCollector = false;
        $titleFieldCreate->isSearchable = true;
        $titleFieldCreate->defaultValue = 'New text line';
        $titleFieldCreate->validatorConfiguration = array('StringLengthValidator' => array('maxStringLength' => 255, 'minStringLength' => 128));
        //$titleFieldCreate->fieldSettings
        $typeCreateStruct->addFieldDefinition($titleFieldCreate);
        $bodyFieldCreate = $contentTypeService->newFieldDefinitionCreateStruct('body', 'eztext');
        $bodyFieldCreate->names = array('eng-US' => 'American body field name', 'eng-GB' => 'British body field name');
        $bodyFieldCreate->descriptions = array('eng-US' => 'American body field description', 'eng-GB' => 'British body field description');
        $bodyFieldCreate->fieldGroup = 'blog-content';
        $bodyFieldCreate->position = 2;
        $bodyFieldCreate->isTranslatable = true;
        $bodyFieldCreate->isRequired = false;
        $bodyFieldCreate->isInfoCollector = false;
        $bodyFieldCreate->isSearchable = false;
        $bodyFieldCreate->defaultValue = '';
        //$bodyFieldCreate->validatorConfiguration
        $bodyFieldCreate->fieldSettings = array('textRows' => 80);
        $typeCreateStruct->addFieldDefinition($bodyFieldCreate);
        $groups = $this->createGroups();
        $type = $contentTypeService->createContentType($typeCreateStruct, $groups);
        if ($publish !== true) {
            return $type;
        }
        $contentTypeService->publishContentTypeDraft($type);
        return $contentTypeService->loadContentType($type->id);
    }
ContentTypeBase