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); }
public function processPublish(FormActionEvent $event) { /** @var \EzSystems\RepositoryForms\Data\Content\ContentCreateData|\EzSystems\RepositoryForms\Data\Content\ContentUpdateData $data */ $data = $event->getData(); $form = $event->getForm(); $draft = $this->saveDraft($data, $form->getConfig()->getOption('languageCode')); $content = $this->contentService->publishVersion($draft->versionInfo); // Redirect to the provided URL. Defaults to URLAlias of the published content. $redirectUrl = $form['redirectUrlAfterPublish']->getData() ?: $this->router->generate(UrlAliasRouter::URL_ALIAS_ROUTE_NAME, ['contentId' => $content->id], UrlGeneratorInterface::ABSOLUTE_URL); $event->setResponse(new RedirectResponse($redirectUrl)); }
/** * @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; }
/** * Publishes a content version * * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to publish this version * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is not a draft * * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo * * @return \eZ\Publish\API\Repository\Values\Content\Content */ public function publishVersion( VersionInfo $versionInfo ) { $returnValue = $this->service->publishVersion( $versionInfo ); $this->signalDispatcher->emit( new PublishVersionSignal( array( 'contentId' => $versionInfo->getContentInfo()->id, 'versionNo' => $versionInfo->versionNo, ) ) ); return $returnValue; }
/** * Publishes a content draft. * * @param eZ\Publish\API\Repository\Values\Content\Content $content */ public function publishDraft(Content $content) { $this->contentService->publishVersion($content->versionInfo->id); }