/** * Renders all format download links. * * @param \TYPO3\CMS\Documentation\Domain\Model\DocumentTranslation $documentTranslation * @return string */ public function render(\TYPO3\CMS\Documentation\Domain\Model\DocumentTranslation $documentTranslation) { $output = ''; foreach ($documentTranslation->getFormats() as $format) { /** @var \TYPO3\CMS\Documentation\Domain\Model\DocumentFormat $format */ $output .= '<a '; $uri = '../' . $format->getPath(); $extension = substr($uri, strrpos($uri, '.') + 1); if (strlen($extension) < 5) { // This is direct link to a file $output .= 'href="' . $uri . '"'; } else { $extension = $format->getFormat(); if ($extension === 'json') { $extension = 'js'; } $output .= 'href="#" onclick="top.TYPO3.Backend.ContentContainer.setUrl(\'' . $uri . '\')"'; } $xliff = 'LLL:EXT:documentation/Resources/Private/Language/locallang.xlf'; $title = sprintf($GLOBALS['LANG']->sL($xliff . ':tx_documentation_domain_model_documentformat.format.title'), $format->getFormat()); $output .= ' title="' . htmlspecialchars($title) . '">'; $spriteIconHtml = \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIconForFile($extension); $output .= $spriteIconHtml . '</a>' . LF; } return $output; }
/** * @test */ public function removeFormatFromObjectStorageHoldingFormats() { $format = new \TYPO3\CMS\Documentation\Domain\Model\DocumentFormat(); $localObjectStorage = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage(); $localObjectStorage->attach($format); $localObjectStorage->detach($format); $this->subject->addFormat($format); $this->subject->removeFormat($format); $this->assertEquals($localObjectStorage, $this->subject->getFormats()); }