Ejemplo n.º 1
0
 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);
 }
 /**
  * @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;
 }
 /**
  * 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;
 }
 /**
  * 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));
 }
Ejemplo n.º 5
0
 /**
  * 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;
 }