/** * Handles content requests per node or object ID * * Requests: * - GET /api/content/node/XXX * - GET /api/content/object/XXX * * Optional HTTP parameters: * - translation=xxx-XX: an optionally forced locale to return * * @return ezpRestMvcResult */ public function doViewContent() { $this->setDefaultResponseGroups(array(self::VIEWCONTENT_RESPONSEGROUP_METADATA)); $isNodeRequested = false; if (isset($this->nodeId)) { $content = ezpContent::fromNodeId($this->nodeId); $isNodeRequested = true; } else { if (isset($this->objectId)) { $content = ezpContent::fromObjectId($this->objectId); } } $result = new ezpRestMvcResult(); // translation parameter if ($this->hasContentVariable('Translation')) { $content->setActiveLanguage($this->getContentVariable('Translation')); } // Handle metadata if ($this->hasResponseGroup(self::VIEWCONTENT_RESPONSEGROUP_METADATA)) { $objectMetadata = ezpRestContentModel::getMetadataByContent($content); if ($isNodeRequested) { $nodeMetadata = ezpRestContentModel::getMetadataByLocation(ezpContentLocation::fetchByNodeId($this->nodeId)); $objectMetadata = array_merge($objectMetadata, $nodeMetadata); } $result->variables['metadata'] = $objectMetadata; } // Handle locations if requested if ($this->hasResponseGroup(self::VIEWCONTENT_RESPONSEGROUP_LOCATIONS)) { $result->variables['locations'] = ezpRestContentModel::getLocationsByContent($content); } // Handle fields content if requested if ($this->hasResponseGroup(self::VIEWCONTENT_RESPONSEGROUP_FIELDS)) { $result->variables['fields'] = ezpRestContentModel::getFieldsByContent($content); } // Add links to fields resources $result->variables['links'] = ezpRestContentModel::getFieldsLinksByContent($content, $this->request); if ($outputFormat = $this->getContentVariable('OutputFormat')) { $renderer = ezpRestContentRenderer::getRenderer($outputFormat, $content, $this); $result->variables['renderedOutput'] = $renderer->render(); } return $result; }
/** * Tests service links for content fields * @group restContentServices * @dataProvider requestObjectProvider * @param ezpRestRequest $request * @param int $nodeId */ public function testFieldsLinksByContent(ezpRestRequest $request, $nodeId) { $mvcConfig = new ezpMvcConfiguration(); $mvcConfig->runPreRoutingFilters($request); $baseUri = $request->getBaseURI(); $contentQueryString = $request->getContentQueryString(true); $content = ezpContent::fromNodeId($nodeId); $links = ezpRestContentModel::getFieldsLinksByContent($content, $request); self::assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_ARRAY, $links); self::assertArrayHasKey('*', $links, 'Links for fields services must contain a wildcard (*) pointing to a service listing all fields content'); // * stands for all fields self::assertEquals($baseUri . '/fields' . $contentQueryString, $links['*']); // We must have one entry per field foreach ($content->fields as $fieldName => $field) { self::assertArrayHasKey($fieldName, $links, "Service link missing for {$fieldName}"); self::assertEquals($baseUri . '/field/' . $fieldName . $contentQueryString, $links[$fieldName], "Wrong service link for {$fieldName}"); } }