本文整理汇总了PHP中eZ\Publish\API\Repository\ContentTypeService类的典型用法代码示例。如果您正苦于以下问题:PHP ContentTypeService类的具体用法?PHP ContentTypeService怎么用?PHP ContentTypeService使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ContentTypeService类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: parse
/**
* Parse input structure.
*
* @param array $data
* @param \eZ\Publish\Core\REST\Common\Input\ParsingDispatcher $parsingDispatcher
*
* @return \eZ\Publish\API\Repository\Values\User\UserCreateStruct
*/
public function parse(array $data, ParsingDispatcher $parsingDispatcher)
{
$contentType = null;
if (array_key_exists('ContentType', $data) && is_array($data['ContentType'])) {
if (!array_key_exists('_href', $data['ContentType'])) {
throw new Exceptions\Parser("Missing '_href' attribute for ContentType element in UserCreate.");
}
$contentType = $this->contentTypeService->loadContentType($this->requestParser->parseHref($data['ContentType']['_href'], 'contentTypeId'));
}
if (!array_key_exists('mainLanguageCode', $data)) {
throw new Exceptions\Parser("Missing 'mainLanguageCode' element for UserCreate.");
}
if (!array_key_exists('login', $data)) {
throw new Exceptions\Parser("Missing 'login' element for UserCreate.");
}
if (!array_key_exists('email', $data)) {
throw new Exceptions\Parser("Missing 'email' element for UserCreate.");
}
if (!array_key_exists('password', $data)) {
throw new Exceptions\Parser("Missing 'password' element for UserCreate.");
}
$userCreateStruct = $this->userService->newUserCreateStruct($data['login'], $data['email'], $data['password'], $data['mainLanguageCode'], $contentType);
if (array_key_exists('Section', $data) && is_array($data['Section'])) {
if (!array_key_exists('_href', $data['Section'])) {
throw new Exceptions\Parser("Missing '_href' attribute for Section element in UserCreate.");
}
$userCreateStruct->sectionId = $this->requestParser->parseHref($data['Section']['_href'], 'sectionId');
}
if (array_key_exists('remoteId', $data)) {
$userCreateStruct->remoteId = $data['remoteId'];
}
if (array_key_exists('enabled', $data)) {
$userCreateStruct->enabled = $this->parserTools->parseBooleanValue($data['enabled']);
}
if (!array_key_exists('fields', $data) || !is_array($data['fields']) || !is_array($data['fields']['field'])) {
throw new Exceptions\Parser("Missing or invalid 'fields' element for UserCreate.");
}
foreach ($data['fields']['field'] as $fieldData) {
if (!array_key_exists('fieldDefinitionIdentifier', $fieldData)) {
throw new Exceptions\Parser("Missing 'fieldDefinitionIdentifier' element in field data for UserCreate.");
}
$fieldDefinition = $userCreateStruct->contentType->getFieldDefinition($fieldData['fieldDefinitionIdentifier']);
if (!$fieldDefinition) {
throw new Exceptions\Parser("'{$fieldData['fieldDefinitionIdentifier']}' is invalid field definition identifier for '{$userCreateStruct->contentType->identifier}' content type in UserCreate.");
}
if (!array_key_exists('fieldValue', $fieldData)) {
throw new Exceptions\Parser("Missing 'fieldValue' element for '{$fieldData['fieldDefinitionIdentifier']}' identifier in UserCreate.");
}
$fieldValue = $this->fieldTypeParser->parseValue($fieldDefinition->fieldTypeIdentifier, $fieldData['fieldValue']);
$languageCode = null;
if (array_key_exists('languageCode', $fieldData)) {
$languageCode = $fieldData['languageCode'];
}
$userCreateStruct->setField($fieldData['fieldDefinitionIdentifier'], $fieldValue, $languageCode);
}
return $userCreateStruct;
}
示例2: getHandler
/**
* Returns form handler to use at $location
*
* @param \eZ\Publish\API\Repository\Values\Content\Location $location
* @return \Heliopsis\eZFormsBundle\FormHandler\FormHandlerInterface
*/
public function getHandler(Location $location)
{
$locationContentTypeId = $location->contentInfo->contentTypeId;
/** @var ContentType $locationContentType */
$locationContentType = $this->contentTypeService->loadContentType($locationContentTypeId);
return array_key_exists($locationContentType->identifier, $this->map) ? $this->map[$locationContentType->identifier] : new NullHandler();
}
示例3: getContentCreateStruct
/**
* Creates and prepares content create structure.
*
* @param array $data
* @return \eZ\Publish\API\Repository\Values\Content\ContentCreateStruct
*/
private function getContentCreateStruct($data)
{
$contentType = $this->contentTypeService->loadContentTypeByIdentifier($data['content_type']);
$struct = $this->contentService->newContentCreateStruct($contentType, '');
$this->fillValueObject($struct, $data, ['content_type']);
return $struct;
}
示例4: updateFieldDefinition
public function updateFieldDefinition($identifier, FieldDefinitionUpdateStruct $fieldDefinitionUpdateStruct)
{
$contentTypeDraft = $this->contentTypeService->createContentTypeDraft($this->currentContentType);
$this->contentTypeService->updateFieldDefinition($contentTypeDraft, $this->currentContentType->getFieldDefinition($identifier), $fieldDefinitionUpdateStruct);
$this->contentTypeService->publishContentTypeDraft($contentTypeDraft);
$this->currentContentType = $this->contentTypeService->loadContentTypeByIdentifier($this->currentContentType->identifier);
}
示例5: parseFieldValue
/**
* Parses the given $value for the field $fieldDefIdentifier in the content
* identified by $contentInfoId.
*
* @param string $contentInfoId
* @param string $fieldDefIdentifier
* @param mixed $value
*
* @return mixed
*/
public function parseFieldValue($contentInfoId, $fieldDefIdentifier, $value)
{
$contentInfo = $this->contentService->loadContentInfo($contentInfoId);
$contentType = $this->contentTypeService->loadContentType($contentInfo->contentTypeId);
$fieldDefinition = $contentType->getFieldDefinition($fieldDefIdentifier);
return $this->parseValue($fieldDefinition->fieldTypeIdentifier, $value);
}
示例6: visit
/**
* @inheritdoc
*/
public function visit(TreeNodeInterface $node, &$data)
{
$struct = $this->contentTypeService->newFieldDefinitionCreateStruct('', '');
$this->fillValueObject($struct, $data);
// Get position from node index (starts from 1)
$struct->position = $node->getIndex() + 1;
return $struct;
}
示例7: parse
/**
* Parse input structure.
*
* @param array $data
* @param \eZ\Publish\Core\REST\Common\Input\ParsingDispatcher $parsingDispatcher
*
* @return \eZ\Publish\Core\REST\Server\Values\Version
*/
public function parse(array $data, ParsingDispatcher $parsingDispatcher)
{
$contentId = $this->requestParser->parseHref($data['VersionInfo']['Content']['_href'], 'contentId');
$content = $this->contentService->loadContent($contentId, null, $data['VersionInfo']['versionNo']);
$contentType = $this->contentTypeService->loadContentType($content->contentInfo->contentTypeId);
$relations = $this->contentService->loadRelations($content->versionInfo);
return new VersionValue($content, $contentType, $relations);
}
示例8: parse
/**
* Parses input structure to a Criterion object
*
* @param array $data
* @param \eZ\Publish\Core\REST\Common\Input\ParsingDispatcher $parsingDispatcher
*
* @throws \eZ\Publish\Core\REST\Common\Exceptions\Parser
*
* @return \eZ\Publish\API\Repository\Values\Content\Query\Criterion\ContentTypeId
*/
public function parse(array $data, ParsingDispatcher $parsingDispatcher)
{
if (!array_key_exists("ContentTypeIdentifierCriterion", $data)) {
throw new Exceptions\Parser("Invalid <ContentTypeIdCriterion> format");
}
$contentType = $this->contentTypeService->loadContentTypeByIdentifier($data["ContentTypeIdentifierCriterion"]);
return new ContentTypeIdCriterion($contentType->id);
}
示例9: mapContentInfo
/**
* Maps Repository ContentInfo to the Site ContentInfo.
*
* @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo
* @param string $languageCode
* @param \eZ\Publish\API\Repository\Values\ContentType\ContentType|null $contentType
*
* @return \Netgen\EzPlatformSiteApi\API\Values\ContentInfo
*/
public function mapContentInfo(VersionInfo $versionInfo, $languageCode, ContentType $contentType = null)
{
$contentInfo = $versionInfo->contentInfo;
if ($contentType === null) {
$contentType = $this->contentTypeService->loadContentType($contentInfo->contentTypeId);
}
return new ContentInfo(['name' => $versionInfo->getName($languageCode), 'languageCode' => $languageCode, 'innerContentInfo' => $versionInfo->contentInfo, 'innerContentType' => $contentType]);
}
示例10: getSelectionChoices
protected function getSelectionChoices()
{
$contentTypeChoices = [];
foreach ($this->contentTypeService->loadContentTypeGroups() as $group) {
foreach ($this->contentTypeService->loadContentTypes($group) as $contentType) {
$contentTypeChoices[$contentType->id] = $contentType->getName($contentType->mainLanguageCode);
}
}
return $contentTypeChoices;
}
示例11: buildForm
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('contentTypeGroupId', 'hidden', ['constraints' => new Callback(function ($contentTypeGroupId, ExecutionContextInterface $context) {
try {
$this->contentTypeService->loadContentTypeGroup($contentTypeGroupId);
} catch (NotFoundException $e) {
$context->buildViolation('content_type.error.content_type_group.not_found')->setParameter('%id%', $contentTypeGroupId)->addViolation();
}
})])->add('create', 'submit', ['label' => 'content_type.create']);
}
示例12: getForm
/**
* @param Location $location
* @return \Symfony\Component\Form\FormInterface
* @throws \Heliopsis\eZFormsBundle\Exceptions\UnknownFormException
*/
public function getForm(Location $location)
{
$locationContentTypeId = $location->contentInfo->contentTypeId;
/** @var ContentType $locationContentType */
$locationContentType = $this->contentTypeService->loadContentType($locationContentTypeId);
if (!array_key_exists($locationContentType->identifier, $this->map)) {
throw new UnknownFormException(sprintf("No form could be mapped to content type identifier '%s'", $locationContentType->identifier));
}
return $this->formFactory->create($this->map[$locationContentType->identifier]);
}
示例13: parse
/**
* Parses input structure to a Criterion object.
*
* @param array $data
* @param \eZ\Publish\Core\REST\Common\Input\ParsingDispatcher $parsingDispatcher
*
* @throws \eZ\Publish\Core\REST\Common\Exceptions\Parser
*
* @return \eZ\Publish\API\Repository\Values\Content\Query\Criterion\ContentTypeId
*/
public function parse(array $data, ParsingDispatcher $parsingDispatcher)
{
if (!array_key_exists('ContentTypeIdentifierCriterion', $data)) {
throw new Exceptions\Parser('Invalid <ContentTypeIdCriterion> format');
}
if (!is_array($data['ContentTypeIdentifierCriterion'])) {
$data['ContentTypeIdentifierCriterion'] = [$data['ContentTypeIdentifierCriterion']];
}
return new ContentTypeIdCriterion(array_map(function ($contentTypeIdentifier) {
return $this->contentTypeService->loadContentTypeByIdentifier($contentTypeIdentifier)->id;
}, $data['ContentTypeIdentifierCriterion']));
}
示例14: processUpdate
public function processUpdate(FormActionEvent $event)
{
/** @var \EzSystems\RepositoryForms\Data\ContentTypeGroup\ContentTypeGroupUpdateData|\EzSystems\RepositoryForms\Data\ContentTypeGroup\ContentTypeGroupCreateData $data */
$data = $event->getData();
if ($data->isNew()) {
$contentTypeGroup = $this->contentTypeService->createContentTypeGroup($data);
} else {
$this->contentTypeService->updateContentTypeGroup($data->contentTypeGroup, $data);
$contentTypeGroup = $this->contentTypeService->loadContentTypeGroup($data->getId());
}
$data->setContentTypeGroup($contentTypeGroup);
}
示例15: parse
/**
* Parse input structure.
*
* @param array $data
* @param \eZ\Publish\Core\REST\Common\Input\ParsingDispatcher $parsingDispatcher
*
* @return \eZ\Publish\API\Repository\Values\ContentType\ContentTypeUpdateStruct
*/
public function parse(array $data, ParsingDispatcher $parsingDispatcher)
{
$contentTypeUpdateStruct = $this->contentTypeService->newContentTypeUpdateStruct();
if (array_key_exists('identifier', $data)) {
$contentTypeUpdateStruct->identifier = $data['identifier'];
}
if (array_key_exists('mainLanguageCode', $data)) {
$contentTypeUpdateStruct->mainLanguageCode = $data['mainLanguageCode'];
}
if (array_key_exists('remoteId', $data)) {
$contentTypeUpdateStruct->remoteId = $data['remoteId'];
}
if (array_key_exists('urlAliasSchema', $data)) {
$contentTypeUpdateStruct->urlAliasSchema = $data['urlAliasSchema'];
}
if (array_key_exists('nameSchema', $data)) {
$contentTypeUpdateStruct->nameSchema = $data['nameSchema'];
}
if (array_key_exists('isContainer', $data)) {
$contentTypeUpdateStruct->isContainer = $this->parserTools->parseBooleanValue($data['isContainer']);
}
if (array_key_exists('defaultSortField', $data)) {
$contentTypeUpdateStruct->defaultSortField = $this->parserTools->parseDefaultSortField($data['defaultSortField']);
}
if (array_key_exists('defaultSortOrder', $data)) {
$contentTypeUpdateStruct->defaultSortOrder = $this->parserTools->parseDefaultSortOrder($data['defaultSortOrder']);
}
if (array_key_exists('defaultAlwaysAvailable', $data)) {
$contentTypeUpdateStruct->defaultAlwaysAvailable = $this->parserTools->parseBooleanValue($data['defaultAlwaysAvailable']);
}
if (array_key_exists('names', $data)) {
if (!is_array($data['names']) || !array_key_exists('value', $data['names']) || !is_array($data['names']['value'])) {
throw new Exceptions\Parser("Invalid 'names' element for ContentTypeUpdate.");
}
$contentTypeUpdateStruct->names = $this->parserTools->parseTranslatableList($data['names']);
}
if (array_key_exists('descriptions', $data)) {
if (!is_array($data['descriptions']) || !array_key_exists('value', $data['descriptions']) || !is_array($data['descriptions']['value'])) {
throw new Exceptions\Parser("Invalid 'descriptions' element for ContentTypeUpdate.");
}
$contentTypeUpdateStruct->descriptions = $this->parserTools->parseTranslatableList($data['descriptions']);
}
if (array_key_exists('modificationDate', $data)) {
$contentTypeUpdateStruct->modificationDate = new DateTime($data['modificationDate']);
}
if (array_key_exists('User', $data)) {
if (!array_key_exists('_href', $data['User'])) {
throw new Exceptions\Parser("Missing '_href' attribute for User element in ContentTypeUpdate.");
}
$contentTypeUpdateStruct->modifierId = $this->requestParser->parseHref($data['User']['_href'], 'userId');
}
return $contentTypeUpdateStruct;
}