Created
September 5, 2012 09:48
-
-
Save pspanja/3634257 to your computer and use it in GitHub Desktop.
Create ContentType
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @var \eZ\Publish\API\Container $serviceContainer | |
*/ | |
$serviceContainer = require "bootstrap.php"; | |
/** | |
* @var $repository \eZ\Publish\API\Repository\Repository | |
*/ | |
$repository = $serviceContainer->getRepository(); | |
$administratorUser = $repository->getUserService()->loadUser( 14 ); | |
$repository->setCurrentUser( $administratorUser ); | |
// CREATE CONTENT TYPE | |
$contentTypeService = $repository->getContentTypeService(); | |
$contentTypeCreateStruct = $contentTypeService->newContentTypeCreateStruct( "project" ); | |
$contentTypeCreateStruct->mainLanguageCode = "eng-GB"; | |
$contentTypeCreateStruct->remoteId = "384b94a1bd6bc06826410e284dd9684887bf56fc"; | |
$contentTypeCreateStruct->urlAliasSchema = "<title>"; | |
$contentTypeCreateStruct->nameSchema = "<title>"; | |
$contentTypeCreateStruct->names = array( | |
"eng-GB" => "Project", | |
); | |
$contentTypeCreateStruct->descriptions = array( | |
"eng-GB" => "A project", | |
); | |
$contentTypeCreateStruct->creatorId = $repository->getCurrentUser()->id; | |
$contentTypeCreateStruct->creationDate = $repository->createDateTime(); | |
// title field definition | |
$titleFieldCreateStruct = $contentTypeService->newFieldDefinitionCreateStruct( | |
"title", "ezstring" | |
); | |
$titleFieldCreateStruct->names = array( | |
"eng-GB" => "Title", | |
); | |
$titleFieldCreateStruct->descriptions = array( | |
"eng-GB" => "Title of the project", | |
); | |
$titleFieldCreateStruct->fieldGroup = "project-content"; | |
$titleFieldCreateStruct->position = 1; | |
$titleFieldCreateStruct->isTranslatable = true; | |
$titleFieldCreateStruct->isRequired = true; | |
$titleFieldCreateStruct->isInfoCollector = false; | |
$titleFieldCreateStruct->validatorConfiguration = array( | |
"StringLengthValidator" => array( | |
"minStringLength" => 0, | |
"maxStringLength" => 0, | |
), | |
); | |
$titleFieldCreateStruct->fieldSettings = array(); | |
$titleFieldCreateStruct->isSearchable = true; | |
$contentTypeCreateStruct->addFieldDefinition( $titleFieldCreateStruct ); | |
// version field definition | |
$versionFieldCreateStruct = $contentTypeService->newFieldDefinitionCreateStruct( | |
"version", "ezinteger" | |
); | |
$versionFieldCreateStruct->names = array( | |
"eng-GB" => "Version", | |
); | |
$versionFieldCreateStruct->descriptions = array( | |
"eng-GB" => "Version of the project", | |
); | |
$versionFieldCreateStruct->fieldGroup = "project-content"; | |
$versionFieldCreateStruct->position = 2; | |
$versionFieldCreateStruct->isTranslatable = true; | |
$versionFieldCreateStruct->isRequired = true; | |
$versionFieldCreateStruct->isInfoCollector = false; | |
$versionFieldCreateStruct->validatorConfiguration = array( | |
"IntegerValueValidator" => array( | |
"minIntegerValue" => 5, | |
"maxIntegerValue" => 0, | |
), | |
); | |
$versionFieldCreateStruct->fieldSettings = array(); | |
$versionFieldCreateStruct->isSearchable = true; | |
$contentTypeCreateStruct->addFieldDefinition( $versionFieldCreateStruct ); | |
$groups = array( | |
$contentTypeService->loadContentTypeGroup( 1 ), | |
); | |
$contentTypeDraft = $contentTypeService->createContentType( | |
$contentTypeCreateStruct, | |
$groups | |
); | |
$contentTypeService->publishContentTypeDraft( $contentTypeDraft ); | |
$contentType = $contentTypeService->loadContentType( $contentTypeDraft->id ); | |
var_dump( $contentType ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment