| 1 | <?php |
||
| 2 | namespace EWW\Dpf\ViewHelpers\Link; |
||
| 3 | |||
| 4 | /* |
||
| 5 | * This file is part of the TYPO3 CMS project. |
||
| 6 | * |
||
| 7 | * It is free software; you can redistribute it and/or modify it under |
||
| 8 | * the terms of the GNU General Public License, either version 2 |
||
| 9 | * of the License, or any later version. |
||
| 10 | * |
||
| 11 | * For the full copyright and license information, please read the |
||
| 12 | * LICENSE.txt file that was distributed with this source code. |
||
| 13 | * |
||
| 14 | * The TYPO3 project - inspiring people to share! |
||
| 15 | */ |
||
| 16 | |||
| 17 | use TYPO3\CMS\Core\Utility\MathUtility; |
||
| 18 | use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper |
||
| 19 | |||
| 20 | class DataCiteViewHelper extends AbstractViewHelper |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 21 | { |
||
| 22 | /** |
||
| 23 | * @var \TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder |
||
| 24 | * @TYPO3\CMS\Extbase\Annotation\Inject |
||
| 25 | */ |
||
| 26 | protected $uriBuilder; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * documentRepository |
||
| 30 | * |
||
| 31 | * @var \EWW\Dpf\Domain\Repository\DocumentRepository |
||
| 32 | * @TYPO3\CMS\Extbase\Annotation\Inject |
||
| 33 | */ |
||
| 34 | protected $documentRepository; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * escapeOutput, activates / deactivates HTML escaping. |
||
| 38 | * |
||
| 39 | * @var bool |
||
| 40 | */ |
||
| 41 | protected $escapeOutput = false; |
||
| 42 | |||
| 43 | /** |
||
| 44 | * Returns the View Icon with link |
||
| 45 | * @param integer $viewPage Detail View page id |
||
| 46 | * @param integer $apiPid |
||
| 47 | * @param string $insideText |
||
| 48 | * @param string $class |
||
| 49 | * @return string html output |
||
| 50 | */ |
||
| 51 | protected function getViewIcon($row, $pageUid, $apiPid, $insideText, $class) |
||
| 52 | { |
||
| 53 | $dataCite = $this->uriBuilder |
||
| 54 | ->reset() |
||
| 55 | ->setTargetPageUid($apiPid) |
||
| 56 | ->setArguments(array( 'tx_dpf' => $row)) |
||
| 57 | ->setCreateAbsoluteUri(true) |
||
| 58 | ->setUseCacheHash(FALSE) |
||
| 59 | ->buildFrontendUri(); |
||
| 60 | |||
| 61 | $title = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('manager.tooltip.datacite', 'dpf', $arguments = null); |
||
| 62 | $icon = '<a href="' . $dataCite . '" data-toggle="tooltip" class="' . $class . '" title="' . $title . '">' . $insideText . '</a>'; |
||
| 63 | |||
| 64 | return $icon; |
||
| 65 | } |
||
| 66 | |||
| 67 | public function initializeArguments() |
||
| 68 | { |
||
| 69 | parent::initializeArguments(); |
||
| 70 | |||
| 71 | $this->registerArgument('arguments', 'array', '', true); |
||
| 72 | $this->registerArgument('pageUid', 'int', '', true); |
||
| 73 | $this->registerArgument('apiPid', 'int', '', true); |
||
| 74 | $this->registerArgument('class', 'string', '', true); |
||
| 75 | } |
||
| 76 | |||
| 77 | /** |
||
| 78 | * Renders a record list as known from the TYPO3 list module |
||
| 79 | * Note: This feature is experimental! |
||
| 80 | * |
||
| 81 | * @return string the rendered record list |
||
| 82 | */ |
||
| 83 | public function render() |
||
| 84 | { |
||
| 85 | $arguments = $this->arguments['arguments']; |
||
| 86 | $pageUid = $this->arguments['pageUid']; |
||
| 87 | $apiPid = $this->arguments['apiPid']; |
||
| 88 | $class = $this->arguments['class']; |
||
| 89 | |||
| 90 | if ($arguments['document']) { |
||
| 91 | |||
| 92 | // it's already a document object? |
||
| 93 | if ($arguments['document'] instanceof \EWW\Dpf\Domain\Model\Document) { |
||
| 94 | |||
| 95 | $document = $arguments['document']; |
||
| 96 | |||
| 97 | } else if (MathUtility::canBeInterpretedAsInteger($arguments['document'])) { |
||
| 98 | |||
| 99 | $document = $this->documentRepository->findByUid($arguments['document']); |
||
| 100 | |||
| 101 | } |
||
| 102 | |||
| 103 | // we found a valid document |
||
| 104 | if ($document) { |
||
| 105 | |||
| 106 | $row['qid'] = $document->getUid(); |
||
| 107 | |||
| 108 | $row['action'] = 'dataCite'; |
||
| 109 | |||
| 110 | } else { |
||
| 111 | |||
| 112 | // ok, nothing to render. So return empty content. |
||
| 113 | return ''; |
||
| 114 | |||
| 115 | } |
||
| 116 | |||
| 117 | } else if ($arguments['documentObjectIdentifier']) { |
||
| 118 | |||
| 119 | $row['action'] = 'dataCite'; |
||
| 120 | |||
| 121 | $row['qid'] = $arguments['documentObjectIdentifier']; |
||
| 122 | |||
| 123 | } |
||
| 124 | |||
| 125 | $insideText = $this->renderChildren(); |
||
| 126 | $content = $this->getViewIcon($row, $pageUid, $apiPid, $insideText, $class); |
||
| 127 | |||
| 128 | return $content; |
||
| 129 | |||
| 130 | } |
||
| 131 | } |
||
| 132 |