Created
September 5, 2012 10:01
-
-
Save gggeek/3634369 to your computer and use it in GitHub Desktop.
eZP 5 content type creation exampe - the barebones
This file contains hidden or 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 | |
// Nb: we assume that scripts are run from root dir, same as eZP4 | |
/** | |
* @var \eZ\Publish\API\Container $SC | |
*/ | |
$SC = require('bootstrap.php'); | |
// Log in as Admin | |
$repo = $SC->getRepository(); | |
$adminUser = $repo->getUserService()->loadUser( 14 ); | |
$repo->setCurrentUser( $adminUser ); | |
// *** Create a content type *** | |
$CTService = $repo->getContentTypeService(); | |
$CTStruct = $CTService->newContentTypeCreateStruct( "testclass" ); | |
// seems this is mandatory | |
$CTStruct->mainLanguageCode = "eng-GB"; | |
// and this one is a good idea as well, or in admin interface class will be hard to use | |
// as it will show up with no name = no link to click on | |
$CTStruct->names = array( | |
"eng-GB" => "testClass", | |
); | |
// Having at least one field is required. | |
// This is the simplest field definition we can get away with | |
$titleFieldCreateStruct = $CTService->newFieldDefinitionCreateStruct( "title", "ezstring" ); | |
$CTStruct->addFieldDefinition( $titleFieldCreateStruct ); | |
// And making objects of this class get a meaningful name is a good idea as well | |
$CTStruct->nameSchema = "<title>"; | |
// publish class. At least 1 group is required. Note that this is a 2-step process | |
// nb: currently group identifier === group name (no lowercasing) | |
$CTGroups = array( $CTService->loadContentTypeGroupByIdentifier ( "Content" ) ); | |
$CTDraft = $CTService->createContentType( $CTStruct, $CTGroups ); | |
$CTStruct = $CTService->publishContentTypeDraft( $CTDraft ); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment