/**
* Prepare content array.
*
* @param array $data
* @param \Symfony\Component\HttpFoundation\Request $request
*
* @return array
*/
protected function prepareContent($data, Request $request)
{
$requestLanguage = $request->get('lang');
$requestedFields = $request->get('fields');
$content = array();
foreach ($data as $contentValue) {
$contentValue = $contentValue->valueObject;
$contentType = $this->contentTypeService->loadContentType($contentValue->contentInfo->contentTypeId);
$location = $this->locationService->loadLocation($contentValue->contentInfo->mainLocationId);
$language = null === $requestLanguage ? $location->contentInfo->mainLanguageCode : $requestLanguage;
$this->value->setFieldDefinitionsList($contentType);
$content[$contentValue->id] = array('contentId' => $contentValue->id, 'contentTypeId' => $contentType->id, 'identifier' => $contentType->identifier, 'language' => $language, 'publishedDate' => $contentValue->contentInfo->publishedDate->format('c'), 'author' => $this->getAuthor($contentValue, $contentType), 'uri' => $this->generator->generate($location, array(), false), 'mainLocation' => array('href' => '/api/ezp/v2/content/locations' . $location->pathString), 'locations' => array('href' => '/api/ezp/v2/content/objects/' . $contentValue->id . '/locations'), 'categoryPath' => $location->pathString, 'fields' => array());
$fields = $this->prepareFields($contentType, $requestedFields);
if (!empty($fields)) {
foreach ($fields as $field) {
$field = $this->value->getConfiguredFieldIdentifier($field, $contentType);
$content[$contentValue->id]['fields'][] = $this->value->getFieldValue($contentValue, $field, $language);
}
}
}
return $content;
}