/** * Creates a new URL alias * * @throws \eZ\Publish\Core\REST\Server\Exceptions\ForbiddenException * @return \eZ\Publish\Core\REST\Server\Values\CreatedURLAlias */ public function createURLAlias() { $urlAliasCreate = $this->inputDispatcher->parse(new Message(array('Content-Type' => $this->request->headers->get('Content-Type')), $this->request->getContent())); if ($urlAliasCreate['_type'] === 'LOCATION') { $locationPathParts = explode('/', $this->requestParser->parseHref($urlAliasCreate['location']['_href'], 'locationPath')); $location = $this->locationService->loadLocation(array_pop($locationPathParts)); try { $createdURLAlias = $this->urlAliasService->createUrlAlias($location, $urlAliasCreate['path'], $urlAliasCreate['languageCode'], $urlAliasCreate['forward'], $urlAliasCreate['alwaysAvailable']); } catch (InvalidArgumentException $e) { throw new ForbiddenException($e->getMessage()); } } else { try { $createdURLAlias = $this->urlAliasService->createGlobalUrlAlias($urlAliasCreate['resource'], $urlAliasCreate['path'], $urlAliasCreate['languageCode'], $urlAliasCreate['forward'], $urlAliasCreate['alwaysAvailable']); } catch (InvalidArgumentException $e) { throw new ForbiddenException($e->getMessage()); } } return new Values\CreatedURLAlias(array('urlAlias' => $createdURLAlias)); }
/** * Create a user chosen $alias pointing to $location in $languageCode. * * This method runs URL filters and transformers before storing them. * Hence the path returned in the URLAlias Value may differ from the given. * $alwaysAvailable makes the alias available in all languages. * * @param \eZ\Publish\API\Repository\Values\Content\Location $location * @param string $path * @param string $languageCode the languageCode for which this alias is valid * @param boolean $forwarding if true a redirect is performed * @param boolean $alwaysAvailable * * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if the path already exists for the given language * * @return \eZ\Publish\API\Repository\Values\Content\URLAlias */ public function createUrlAlias(Location $location, $path, $languageCode, $forwarding = false, $alwaysAvailable = false) { $returnValue = $this->service->createUrlAlias($location, $path, $languageCode, $forwarding, $alwaysAvailable); $this->signalDispatcher->emit(new CreateUrlAliasSignal(array('urlAliasId' => $returnValue->id))); return $returnValue; }