本文整理汇总了PHP中eZ\Publish\API\Repository\ContentService::createContent方法的典型用法代码示例。如果您正苦于以下问题:PHP ContentService::createContent方法的具体用法?PHP ContentService::createContent怎么用?PHP ContentService::createContent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类eZ\Publish\API\Repository\ContentService
的用法示例。
在下文中一共展示了ContentService::createContent方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: handleAction
public function handleAction(Request $request)
{
$user = $this->userService->loadUserByCredentials($request->username, $request->password);
$this->repository->setCurrentUser($user);
$contentCreateStruct = $this->contentProvider->newContentCreateStructFromRequest($request);
$locationCreateStruct = $this->contentProvider->newLocationCreateStructFromRequest($request);
$content = $this->contentService->createContent($contentCreateStruct, array($locationCreateStruct));
$this->contentService->publishVersion($content->versionInfo);
}
示例2: visit
/**
* @inheritdoc
*/
public function visit(TreeNodeInterface $node, &$data)
{
if (!is_array($data)) {
return null;
}
// create structure
$contentStruct = $this->getContentCreateStruct($data);
$locationStruct = $this->getLocationCreateStruct($data, self::DEFAULT_LOCATION_ID);
// publish content object
$draft = $this->contentService->createContent($contentStruct, array($locationStruct));
$publishedContent = $this->contentService->publishVersion($draft->versionInfo);
// Add location to the location list
if (isset($publishedContent->contentInfo)) {
$this->objectCollection->add('locations', $node->getName(), $publishedContent->contentInfo->mainLocationId);
}
// Add content to content list
if (isset($publishedContent->contentInfo)) {
$this->objectCollection->add('content_items', $node->getName(), $publishedContent->id);
}
return $publishedContent;
}
示例3: saveDraft
/**
* Saves content draft corresponding to $data.
* Depending on the nature of $data (create or update data), the draft will either be created or simply updated.
*
* @param ContentStruct|\EzSystems\RepositoryForms\Data\Content\ContentCreateData|\EzSystems\RepositoryForms\Data\Content\ContentUpdateData $data
* @param $languageCode
* @return \eZ\Publish\API\Repository\Values\Content\Content
*/
private function saveDraft(ContentStruct $data, $languageCode)
{
foreach ($data->fieldsData as $fieldDefIdentifier => $fieldData) {
$data->setField($fieldDefIdentifier, $fieldData->value, $languageCode);
}
if ($data->isNew()) {
$contentDraft = $this->contentService->createContent($data, $data->getLocationStructs());
} else {
$contentDraft = $this->contentService->updateContent($data->contentDraft->getVersionInfo(), $data);
}
return $contentDraft;
}
示例4: createContentDraft
/**
* Creates a content draft.
*
* @param eZ\Publish\API\Repository\Values\Content\Location $parentLocationId
* @param string $contentTypeIdentifier
* @param string $languageCode
* @param array $fields Fields, as primitives understood by setField
*
* @return eZ\Publish\API\Repository\Values\Content\Content an unpublished Content draft
*/
public function createContentDraft($parentLocationId, $contentTypeIdentifier, $fields, $languageCode = null)
{
$languageCode = $languageCode ?: self::DEFAULT_LANGUAGE;
$repository = $this->getRepository();
$locationCreateStruct = $repository->getLocationService()->newLocationCreateStruct($parentLocationId);
$contentTypeIdentifier = $this->contentTypeService->loadContentTypeByIdentifier($contentTypeIdentifier);
$contentCreateStruct = $this->contentService->newContentCreateStruct($contentTypeIdentifier, $languageCode);
foreach (array_keys($fields) as $key) {
$contentCreateStruct->setField($key, $fields[$key]);
}
return $this->contentService->createContent($contentCreateStruct, array($locationCreateStruct));
}
示例5: createContent
/**
* Creates a new content draft assigned to the authenticated user.
*
* If a different userId is given in $contentCreateStruct it is assigned to the given user
* but this required special rights for the authenticated user
* (this is useful for content staging where the transfer process does not
* have to authenticate with the user which created the content object in the source server).
* The user has to publish the draft if it should be visible.
* In 4.x at least one location has to be provided in the location creation array.
*
* @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to create the content in the given location
* @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if there is a provided remoteId which exists in the system
* or there is no location provided (4.x) or multiple locations
* are under the same parent or if the a field value is not accepted by the field type
* @throws \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException if a field in the $contentCreateStruct is not valid
* @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException if a required field is missing or is set to an empty value
*
* @param \eZ\Publish\API\Repository\Values\Content\ContentCreateStruct $contentCreateStruct
* @param \eZ\Publish\API\Repository\Values\Content\LocationCreateStruct[] $locationCreateStructs For each location parent under which a location should be created for the content
*
* @return \eZ\Publish\API\Repository\Values\Content\Content - the newly created content draft
*/
public function createContent( ContentCreateStruct $contentCreateStruct, array $locationCreateStructs = array() )
{
$returnValue = $this->service->createContent( $contentCreateStruct, $locationCreateStructs );
$this->signalDispatcher->emit(
new CreateContentSignal(
array(
'contentId' => $returnValue->getVersionInfo()->getContentInfo()->id,
'versionNo' => $returnValue->getVersionInfo()->versionNo,
)
)
);
return $returnValue;
}