public function onKernelRequest(GetResponseEvent $event)
 {
     $request = $event->getRequest();
     if (!$request->attributes->get('is_rest_request')) {
         return;
     }
     if (($contentTypeHeaderValue = $request->headers->get('content-type')) === null) {
         return;
     }
     list($mediaType) = explode('+', $contentTypeHeaderValue);
     if (strtolower($mediaType) == !'application/vnd.ez.api.contentcreate') {
         return;
     }
     $message = $this->buildMessage($request);
     if (!$message->body) {
         return;
     }
     $result = $this->restInputDispatcher->parse($message);
     if (!$result instanceof RestContentCreateStruct) {
         return;
     }
     // Not a user
     if (($userCreateData = $this->mapContentCreateToUserCreate($result)) === false) {
         return;
     }
     list($userCreateStruct, $userGroup) = $userCreateData;
     $createdUser = $this->repository->getUserService()->createUser($userCreateStruct, [$userGroup]);
     $createdContentInfo = $createdUser->contentInfo;
     $createdLocation = $this->repository->getLocationService()->loadLocation($createdContentInfo->mainLocationId);
     $contentType = $this->repository->getContentTypeService()->loadContentType($createdContentInfo->contentTypeId);
     $result = new CreatedContent(array('content' => new RestContent($createdContentInfo, $createdLocation, $this->repository->getContentService()->loadContent($createdContentInfo->id), $contentType, $this->repository->getContentService()->loadRelations($createdUser->getVersionInfo()))));
     $event->setResponse($this->viewDispatcher->dispatch($event->getRequest(), $result));
 }
 /**
  * Detects if there is a custom controller to use to render a Location/Content.
  *
  * @param FilterControllerEvent $event
  *
  * @throws \Symfony\Component\Security\Core\Exception\AccessDeniedException
  */
 public function getController(FilterControllerEvent $event)
 {
     $request = $event->getRequest();
     // Only taking content related controller (i.e. ez_content:viewLocation or ez_content:viewContent)
     if (strpos($request->attributes->get('_controller'), 'ez_content:') === false) {
         return;
     }
     try {
         if ($request->attributes->has('locationId')) {
             $valueObject = $this->repository->getLocationService()->loadLocation($request->attributes->get('locationId'));
         } elseif ($request->attributes->get('location') instanceof Location) {
             $valueObject = $request->attributes->get('location');
             $request->attributes->set('locationId', $valueObject->id);
         } elseif ($request->attributes->has('contentId')) {
             $valueObject = $this->repository->sudo(function (Repository $repository) use($request) {
                 return $repository->getContentService()->loadContentInfo($request->attributes->get('contentId'));
             });
         } elseif ($request->attributes->get('contentInfo') instanceof ContentInfo) {
             $valueObject = $request->attributes->get('contentInfo');
             $request->attributes->set('contentId', $valueObject->id);
         }
     } catch (UnauthorizedException $e) {
         throw new AccessDeniedException();
     }
     if (!isset($valueObject)) {
         $this->logger->error('Could not resolver a view controller, invalid value object to match.');
         return;
     }
     $controllerReference = $this->controllerManager->getControllerReference($valueObject, $request->attributes->get('viewType'));
     if (!$controllerReference instanceof ControllerReference) {
         return;
     }
     $request->attributes->set('_controller', $controllerReference->controller);
     $event->setController($this->controllerResolver->getController($request));
 }
 /**
  * Converts eZ Publish legacy objects and nodes to content and locations
  *
  * @param mixed $object
  *
  * @return mixed
  */
 public function convert($object)
 {
     if ($object instanceof eZContentObject) {
         return $this->repository->getContentService()->loadContent($object->attribute('id'));
     } else {
         if ($object instanceof eZContentObjectTreeNode) {
             return $this->repository->getLocationService()->loadLocation($object->attribute('node_id'));
         }
     }
     return $object;
 }
 /**
  * @param \eZ\Publish\API\Repository\Repository $repository
  * @param ConfigResolverInterface|\Psr\Log\LoggerInterface $resolver
  */
 public function __construct(Repository $repository, ConfigResolverInterface $resolver)
 {
     $this->repository = $repository;
     $this->searchService = $this->repository->getSearchService();
     $this->locationService = $this->repository->getLocationService();
     $this->contentService = $this->repository->getContentService();
     $this->languageService = $this->repository->getContentLanguageService();
     $this->userService = $this->repository->getUserService();
     $this->contentTypeService = $this->repository->getContentTypeService();
     $this->configResolver = $resolver;
 }
 /**
  * Recovers the $trashedLocation at its original place if possible.
  *
  * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to recover the trash item at the parent location location
  *
  * If $newParentLocation is provided, $trashedLocation will be restored under it.
  *
  * @param \eZ\Publish\API\Repository\Values\Content\TrashItem $trashItem
  * @param \eZ\Publish\API\Repository\Values\Content\Location $newParentLocation
  *
  * @return \eZ\Publish\API\Repository\Values\Content\Location the newly created or recovered location
  */
 public function recover(APITrashItem $trashItem, Location $newParentLocation = null)
 {
     if (!is_numeric($trashItem->id)) {
         throw new InvalidArgumentValue("id", $trashItem->id, "TrashItem");
     }
     if ($newParentLocation === null && !is_numeric($trashItem->parentLocationId)) {
         throw new InvalidArgumentValue("parentLocationId", $trashItem->parentLocationId, "TrashItem");
     }
     if ($newParentLocation !== null && !is_numeric($newParentLocation->id)) {
         throw new InvalidArgumentValue("parentLocationId", $newParentLocation->id, "Location");
     }
     if ($this->repository->hasAccess('content', 'restore') !== true) {
         throw new UnauthorizedException('content', 'restore');
     }
     $this->repository->beginTransaction();
     try {
         $newParentLocationId = $newParentLocation ? $newParentLocation->id : $trashItem->parentLocationId;
         $newLocationId = $this->persistenceHandler->trashHandler()->recover($trashItem->id, $newParentLocationId);
         $content = $this->repository->getContentService()->loadContent($trashItem->contentId);
         $urlAliasNames = $this->nameSchemaService->resolveUrlAliasSchema($content);
         // Publish URL aliases for recovered location
         foreach ($urlAliasNames as $languageCode => $name) {
             $this->persistenceHandler->urlAliasHandler()->publishUrlAliasForLocation($newLocationId, $newParentLocationId, $name, $languageCode, $content->contentInfo->alwaysAvailable);
         }
         $this->repository->commit();
     } catch (Exception $e) {
         $this->repository->rollback();
         throw $e;
     }
     return $this->repository->getLocationService()->loadLocation($newLocationId);
 }
 /**
  * Appends destination Content ids of given $fieldValue to the $relation array.
  *
  * If $fieldValue contains Location ids, the will be converted to the Content id that Location encapsulates.
  *
  * @param array $relations
  * @param array $locationIdToContentIdMapping An array with Location Ids as keys and corresponding Content Id as values
  * @param \eZ\Publish\SPI\FieldType\FieldType $fieldType
  * @param \eZ\Publish\Core\FieldType\Value $fieldValue Accepted field value.
  * @param string $fieldDefinitionId
  *
  * @return void
  */
 public function appendFieldRelations(array &$relations, array &$locationIdToContentIdMapping, SPIFieldType $fieldType, BaseValue $fieldValue, $fieldDefinitionId)
 {
     foreach ($fieldType->getRelations($fieldValue) as $relationType => $destinationIds) {
         if ($relationType === Relation::FIELD) {
             if (!isset($relations[$relationType][$fieldDefinitionId])) {
                 $relations[$relationType][$fieldDefinitionId] = array();
             }
             $relations[$relationType][$fieldDefinitionId] += array_flip($destinationIds);
         } else {
             if ($relationType & (Relation::LINK | Relation::EMBED)) {
                 if (!isset($relations[$relationType])) {
                     $relations[$relationType] = array();
                 }
                 if (isset($destinationIds["locationIds"])) {
                     foreach ($destinationIds["locationIds"] as $locationId) {
                         if (!isset($locationIdToContentIdMapping[$locationId])) {
                             $location = $this->repository->getLocationService()->loadLocation($locationId);
                             $locationIdToContentIdMapping[$locationId] = $location->contentId;
                         }
                         $relations[$relationType][$locationIdToContentIdMapping[$locationId]] = true;
                     }
                 }
                 if (isset($destinationIds["contentIds"])) {
                     $relations[$relationType] += array_flip($destinationIds["contentIds"]);
                 }
             }
         }
     }
 }
示例#7
0
 /**
  * Creates an array of SPI location create structs from given array of API location create structs
  *
  * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
  *
  * @param \eZ\Publish\API\Repository\Values\Content\LocationCreateStruct $locationCreateStruct
  * @param \eZ\Publish\API\Repository\Values\Content\Location $parentLocation
  * @param mixed $mainLocation
  * @param mixed $contentId
  * @param mixed $contentVersionNo
  *
  * @return \eZ\Publish\SPI\Persistence\Content\Location\CreateStruct
  */
 public function buildSPILocationCreateStruct($locationCreateStruct, APILocation $parentLocation, $mainLocation, $contentId, $contentVersionNo)
 {
     if ($locationCreateStruct->priority !== null && !is_int($locationCreateStruct->priority)) {
         throw new InvalidArgumentValue("priority", $locationCreateStruct->priority, "LocationCreateStruct");
     }
     if (!is_bool($locationCreateStruct->hidden)) {
         throw new InvalidArgumentValue("hidden", $locationCreateStruct->hidden, "LocationCreateStruct");
     }
     if ($locationCreateStruct->remoteId !== null && (!is_string($locationCreateStruct->remoteId) || empty($locationCreateStruct->remoteId))) {
         throw new InvalidArgumentValue("remoteId", $locationCreateStruct->remoteId, "LocationCreateStruct");
     }
     if ($locationCreateStruct->sortField !== null && !$this->isValidLocationSortField($locationCreateStruct->sortField)) {
         throw new InvalidArgumentValue("sortField", $locationCreateStruct->sortField, "LocationCreateStruct");
     }
     if ($locationCreateStruct->sortOrder !== null && !$this->isValidLocationSortOrder($locationCreateStruct->sortOrder)) {
         throw new InvalidArgumentValue("sortOrder", $locationCreateStruct->sortOrder, "LocationCreateStruct");
     }
     $remoteId = $locationCreateStruct->remoteId;
     if (null === $remoteId) {
         $remoteId = $this->getUniqueHash($locationCreateStruct);
     } else {
         try {
             $this->repository->getLocationService()->loadLocationByRemoteId($remoteId);
             throw new InvalidArgumentException("\$locationCreateStructs", "Another Location with remoteId '{$remoteId}' exists");
         } catch (NotFoundException $e) {
             // Do nothing
         }
     }
     return new SPILocationCreateStruct(array("priority" => $locationCreateStruct->priority, "hidden" => $locationCreateStruct->hidden, "invisible" => $locationCreateStruct->hidden === true || $parentLocation->invisible, "remoteId" => $remoteId, "contentId" => $contentId, "contentVersion" => $contentVersionNo, "pathIdentificationString" => null, "mainLocationId" => $mainLocation, "sortField" => $locationCreateStruct->sortField !== null ? $locationCreateStruct->sortField : Location::SORT_FIELD_NAME, "sortOrder" => $locationCreateStruct->sortOrder !== null ? $locationCreateStruct->sortOrder : Location::SORT_ORDER_ASC, "parentId" => $locationCreateStruct->parentLocationId));
 }
 /**
  * Create a user chosen $alias pointing to a resource in $languageCode.
  *
  * This method does not handle location resources - if a user enters a location target
  * the createCustomUrlAlias method has to be used.
  * This method runs URL filters and 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.
  *
  * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if the path already exists for the given
  *         language or if resource is not valid
  *
  * @param string $resource
  * @param string $path
  * @param string $languageCode
  * @param bool $forwarding
  * @param bool $alwaysAvailable
  *
  * @return \eZ\Publish\API\Repository\Values\Content\URLAlias
  */
 public function createGlobalUrlAlias($resource, $path, $languageCode, $forwarding = false, $alwaysAvailable = false)
 {
     if (!preg_match('#^([a-zA-Z0-9_]+):(.+)$#', $resource, $matches)) {
         throw new InvalidArgumentException('$resource', 'argument is not valid');
     }
     $path = $this->cleanUrl($path);
     if ($matches[1] === 'eznode' || 0 === strpos($resource, 'module:content/view/full/')) {
         if ($matches[1] === 'eznode') {
             $locationId = $matches[2];
         } else {
             $resourcePath = explode('/', $matches[2]);
             $locationId = end($resourcePath);
         }
         return $this->createUrlAlias($this->repository->getLocationService()->loadLocation($locationId), $path, $languageCode, $forwarding, $alwaysAvailable);
     }
     $this->repository->beginTransaction();
     try {
         $spiUrlAlias = $this->urlAliasHandler->createGlobalUrlAlias($matches[1] . ':' . $this->cleanUrl($matches[2]), $path, $forwarding, $languageCode, $alwaysAvailable);
         $this->repository->commit();
     } catch (ForbiddenException $e) {
         $this->repository->rollback();
         throw new InvalidArgumentException('$path', $e->getMessage(), $e);
     } catch (Exception $e) {
         $this->repository->rollback();
         throw $e;
     }
     return $this->buildUrlAliasDomainObject($spiUrlAlias, $path);
 }
示例#9
0
 /**
  * Get Content Location Service
  *
  * Get service object to perform operations on Location objects and subtrees
  *
  * @return \eZ\Publish\API\Repository\LocationService
  */
 public function getLocationService()
 {
     if ($this->locationService !== null) {
         return $this->locationService;
     }
     $this->locationService = new LocationService($this->repository->getLocationService(), $this->signalDispatcher);
     return $this->locationService;
 }
 public function __construct(Repository $repository, CategoryServiceInterface $categoryService, PostServiceInterface $postService)
 {
     $this->repository = $repository;
     $this->categoryService = $categoryService;
     $this->postService = $postService;
     $this->searchService = $repository->getSearchService();
     $this->contentService = $repository->getContentService();
     $this->locationService = $repository->getLocationService();
     $this->contentTypeService = $repository->getContentTypeService();
     $this->userService = $repository->getUserService();
 }
示例#11
0
 /**
  * Builds the domain UserGroup object from provided Content object
  *
  * @param \eZ\Publish\API\Repository\Values\Content\Content $content
  *
  * @return \eZ\Publish\API\Repository\Values\User\UserGroup
  */
 protected function buildDomainUserGroupObject(APIContent $content)
 {
     $locationService = $this->repository->getLocationService();
     $subGroupCount = 0;
     if ($content->getVersionInfo()->getContentInfo()->mainLocationId !== null) {
         $mainLocation = $locationService->loadLocation($content->getVersionInfo()->getContentInfo()->mainLocationId);
         $parentLocation = $locationService->loadLocation($mainLocation->parentLocationId);
         $subGroups = $this->searchSubGroups($mainLocation->id, null, Location::SORT_ORDER_ASC, 0, 0);
         $subGroupCount = $subGroups->totalCount;
     }
     return new UserGroup(array('content' => $content, 'parentId' => isset($parentLocation) ? $parentLocation->contentId : null, 'subGroupCount' => $subGroupCount));
 }
 /**
  * Uses a content type identifier + a hash of fields values
  * to create and publish a draft below the root location.
  *
  * @param string $contentTypeIdentifier
  * @param array $fields Hash of field def identifier => field value
  *
  * @return Content the created draft.
  */
 public function createDraft($contentTypeIdentifier, array $fields)
 {
     $contentService = $this->repository->getContentService();
     $createStruct = $contentService->newContentCreateStruct($this->repository->getContentTypeService()->loadContentTypeByIdentifier($contentTypeIdentifier), 'eng-GB');
     foreach ($fields as $fieldDefIdentifier => $fieldValue) {
         $createStruct->setField($fieldDefIdentifier, $fieldValue);
     }
     $locationCreateStruct = $this->repository->getLocationService()->newLocationCreateStruct(2);
     $this->currentDraft = $this->repository->sudo(function () use($createStruct, $locationCreateStruct) {
         return $this->repository->getContentService()->createContent($createStruct, [$locationCreateStruct]);
     });
     return $this->currentDraft;
 }
 public function testManifestRun()
 {
     // design/plainsite location id
     $parentLocationId = 56;
     $completed = false;
     $location = static::$repository->getLocationService()->loadLocation($parentLocationId);
     $children = static::$repository->getLocationService()->loadLocationChildren($location);
     $this->assertLessThan(4, $children->totalCount);
     $manifest = new GoogleNewsToEzPlatformContentManifest(static::$repository, array('url' => 'https://news.google.com/news?cf=all&hl=en&ned=us&topic=t&output=rss', 'location_id' => $parentLocationId));
     $this->assertInstanceOf(EventDrivenProcessor::class, $manifest->getProcessor());
     $manifest->getProcessor()->addListener(TransferEvents::POST_PROCEDURE, function () use(&$completed) {
         $completed = true;
     });
     $manifest->configureProcessor($manifest->getProcessor());
     $runner = new ManifestRunner($manifest);
     $runner->run($manifest);
     $this->assertTrue($completed);
     $this->assertEquals('googlenews_to_ezplatform_content', $manifest->getName());
     $location = static::$repository->getLocationService()->loadLocation($parentLocationId);
     $children = static::$repository->getLocationService()->loadLocationChildren($location);
     $this->assertGreaterThan(4, $children->totalCount);
 }
 /**
  * Helper to quickly create content.
  *
  * @see https://github.com/ezsystems/CookbookBundle/blob/master/Command/CreateContentCommand.php eZ Publish Cookbook
  *
  * Usage:
  * <code>
  * $this->createContent(2, 'folder', 'eng-GB', [
  *     'title' => 'Folder Title',
  * ]);
  * </code>
  *
  * @param int    $parentLocationId
  * @param string $contentTypeIdentifier
  * @param string $languageCode
  * @param array  $fields
  *
  * @throws NotFoundException               If the content type or parent location could not be found
  * @throws ContentFieldValidationException If an invalid field value has been provided
  * @throws ContentValidationException      If a required field is missing or empty
  *
  * @return Content
  */
 protected function createContent($parentLocationId, $contentTypeIdentifier, $languageCode, array $fields)
 {
     $contentService = $this->repository->getContentService();
     $locationService = $this->repository->getLocationService();
     $contentTypeService = $this->repository->getContentTypeService();
     $contentType = $contentTypeService->loadContentTypeByIdentifier($contentTypeIdentifier);
     $contentCreateStruct = $contentService->newContentCreateStruct($contentType, $languageCode);
     foreach ($fields as $key => $value) {
         $contentCreateStruct->setField($key, $value);
     }
     $locationCreateStruct = $locationService->newLocationCreateStruct($parentLocationId);
     $draft = $contentService->createContent($contentCreateStruct, [$locationCreateStruct]);
     $content = $contentService->publishVersion($draft->getVersionInfo());
     return $content;
 }
 /**
  *  render a viewtemplate with a twigfunction uses the ezpulish  override.yml
  *
  *     {{ cjw_render_location( {'locationId': locationObject.id, 'viewType': 'line'} ) }}
  *
  *     => faster is the following call
  *
  *     {{ cjw_render_location( {'location': locationObject, 'viewType': 'line'} ) }}
  *
  * @param array  $parameters  hash
  *
  * @return string
  */
 public function renderLocation(array $params)
 {
     $viewType = $params['viewType'];
     if (isset($params['location']) && $params['location'] instanceof Location) {
         $location = $params['location'];
         $locationId = $location->id;
     } elseif (isset($params['locationId'])) {
         $locationId = $params['locationId'];
         $location = $this->repository->getLocationService()->loadLocation($locationId);
         if ($location->invisible) {
             throw new NotFoundHttpException("Location #{$locationId} cannot be displayed as it is flagged as invisible.");
         }
     } else {
         // TODO Fehler wenn locationId nicht gesetzt oder location keine Location objekt
         return false;
     }
     $templateFileName = 'CjwPublishToolsBundle::line.html.twig';
     $this->template = $this->environment->loadTemplate($templateFileName);
     $locationObject = $this->repository->getLocationService()->loadLocation($locationId);
     $contentId = $locationObject->contentInfo->id;
     $contentObject = $this->repository->getContentService()->loadContent($contentId);
     // $view = 'CjwPublishToolsBundle::line.html.twig';
     // find override template
     $template = $this->getOverrideTemplate($locationObject, $contentObject, $viewType);
     //var_dump( $template );
     $params['location'] = $locationObject;
     $params['content'] = $contentObject;
     // name of the rendered template
     $params['_template'] = $template;
     // loop params array, and set as tpl var
     if (isset($params['params'])) {
         foreach ($params['params'] as $param => $value) {
             $params[$param] = $value;
         }
     }
     $temapleRenderedContent = $this->getTemplateEngine()->render($template, $params);
     // TODO  wenn templatedebug eingeschaltet ist dieses anzeigen
     if ($this->templateDebug == true) {
         $temapleContentDebug = "\n<!-- cjw_render_location: LocationId: {$locationId}, viewType: {$viewType}, Template: {$template} -->\n";
         $temapleRenderedContent = $temapleContentDebug . "\n" . $temapleRenderedContent;
     }
     return $temapleRenderedContent;
 }
 /**
  * Compute Metas of the Field thanks to its Content and the Fallback
  *
  * @param Field       $field
  * @param ContentInfo $contentInfo
  *
  * @return string
  */
 public function computeMetas(Field $field, ContentInfo $contentInfo)
 {
     $fallback = false;
     $languages = $this->configResolver->getParameter('languages');
     $contentType = $this->eZRepository->getContentTypeService()->loadContentType($contentInfo->contentTypeId);
     $content = $this->eZRepository->getContentService()->loadContentByContentInfo($contentInfo, $languages);
     $contentMetas = $this->innerComputeMetas($content, $field, $contentType, $fallback);
     if ($fallback) {
         $rootNode = $this->eZRepository->getLocationService()->loadLocation($this->configResolver->getParameter("content.tree_root.location_id"));
         $rootContent = $this->eZRepository->getContentService()->loadContentByContentInfo($rootNode->contentInfo, $languages);
         $rootContentType = $this->eZRepository->getContentTypeService()->loadContentType($rootContent->contentInfo->contentTypeId);
         // We need to load the good field too
         $metasIdentifier = $this->configResolver->getParameter('fieldtype_metas_identifier', 'novae_zseo');
         $rootMetas = $this->innerComputeMetas($rootContent, $metasIdentifier, $rootContentType, $fallback);
         foreach ($contentMetas as $key => $metaContent) {
             if (array_key_exists($key, $rootMetas)) {
                 $metaContent->setContent($metaContent->isEmpty() ? $rootMetas[$key]->getContent() : $metaContent->getContent());
             }
         }
     }
     return '';
 }
 /**
  * @param Repository $repository
  * @param int $parentLocationId
  *
  * @return \eZ\Publish\API\Repository\Values\Content\Content
  */
 protected function createNewContentInPlaceTrashedOne(Repository $repository, $parentLocationId)
 {
     $contentService = $repository->getContentService();
     $locationService = $repository->getLocationService();
     $contentTypeService = $repository->getContentTypeService();
     $contentType = $contentTypeService->loadContentTypeByIdentifier('forum');
     $newContent = $contentService->newContentCreateStruct($contentType, 'eng-US');
     $newContent->setField('name', 'Media');
     $location = $locationService->newLocationCreateStruct($parentLocationId);
     $draftContent = $contentService->createContent($newContent, [$location]);
     return $contentService->publishVersion($draftContent->versionInfo);
 }
 /**
  * @param Content $content
  * @return mixed
  */
 public function getContentDecoratorByContent(Content $content)
 {
     $location = $this->repository->getLocationService()->loadLocation($content->contentInfo->mainLocationId);
     return $this->getContentDecorator($location);
 }
示例#19
0
 /**
  * @return \eZ\Publish\API\Repository\LocationService
  */
 protected function getLocationService()
 {
     return $this->apiRepository->getLocationService();
 }
 public function __construct(Repository $repository)
 {
     $this->repository = $repository;
     $this->contentService = $repository->getContentService();
     $this->locationService = $repository->getLocationService();
 }
 /**
  * Creates and returns content with given $fieldData.
  *
  * @param mixed $fieldData
  * @param \eZ\Publish\API\Repository\Repository $repository
  * @param \eZ\Publish\API\Repository\Values\ContentType\ContentType $contentType
  *
  * @return \eZ\Publish\API\Repository\Values\Content\Content
  */
 protected function createTestSearchContent($fieldData, Repository $repository, $contentType)
 {
     $contentService = $repository->getContentService();
     $locationService = $repository->getLocationService();
     $createStruct = $contentService->newContentCreateStruct($contentType, 'eng-US');
     $createStruct->setField('name', 'Test object');
     $createStruct->setField('data', $fieldData);
     $locationCreateStruct = $locationService->newLocationCreateStruct(2);
     return $contentService->publishVersion($contentService->createContent($createStruct, array($locationCreateStruct))->versionInfo);
 }