| 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 | use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface; |
||
| 20 | |||
| 21 | class PreviewViewHelper extends AbstractViewHelper |
||
| 22 | { |
||
| 23 | /** |
||
| 24 | * @var \TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface |
||
| 25 | * @TYPO3\CMS\Extbase\Annotation\Inject |
||
| 26 | */ |
||
| 27 | protected $configurationManager; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * @var \TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder |
||
| 31 | * @TYPO3\CMS\Extbase\Annotation\Inject |
||
| 32 | */ |
||
| 33 | protected $uriBuilder; |
||
| 34 | |||
| 35 | /** |
||
| 36 | * documentRepository |
||
| 37 | * |
||
| 38 | * @var \EWW\Dpf\Domain\Repository\DocumentRepository |
||
| 39 | * @TYPO3\CMS\Extbase\Annotation\Inject |
||
| 40 | */ |
||
| 41 | protected $documentRepository; |
||
| 42 | |||
| 43 | /** |
||
| 44 | * Secret API key for delivering inactive documents. |
||
| 45 | * @var string |
||
| 46 | */ |
||
| 47 | private $secretKey; |
||
| 48 | |||
| 49 | |||
| 50 | /** |
||
| 51 | * escapeOutput, activates / deactivates HTML escaping. |
||
| 52 | * |
||
| 53 | * @var bool |
||
| 54 | */ |
||
| 55 | protected $escapeOutput = false; |
||
| 56 | |||
| 57 | |||
| 58 | /** |
||
| 59 | * Initialize secret key from plugin TYPOScript configuration. |
||
| 60 | */ |
||
| 61 | public function initialize() { |
||
| 62 | parent::initialize(); |
||
| 63 | |||
| 64 | $settings = $this->configurationManager->getConfiguration(ConfigurationManagerInterface::CONFIGURATION_TYPE_FULL_TYPOSCRIPT); |
||
| 65 | |||
| 66 | if (isset($settings['plugin.']['tx_dpf.']['settings.']['deliverInactiveSecretKey'])) { |
||
| 67 | $this->secretKey = $settings['plugin.']['tx_dpf.']['settings.']['deliverInactiveSecretKey']; |
||
| 68 | } |
||
| 69 | } |
||
| 70 | |||
| 71 | /** |
||
| 72 | * Returns the View Icon with link |
||
| 73 | * |
||
| 74 | * @param array $row Data row |
||
| 75 | * @param integer $viewPage Detail View page id |
||
| 76 | * @param integer $apiPid |
||
| 77 | * @param string $insideText |
||
| 78 | * @param string $class |
||
| 79 | * @return string html output |
||
| 80 | */ |
||
| 81 | protected function getViewIcon(array $row, $pageUid, $apiPid, $insideText, $class) |
||
| 82 | { |
||
| 83 | |||
| 84 | $previewMets = $this->uriBuilder |
||
| 85 | ->reset() |
||
| 86 | ->setTargetPageUid($apiPid) |
||
| 87 | ->setArguments(array( 'tx_dpf' => $row)) |
||
| 88 | ->setCreateAbsoluteUri(true) |
||
| 89 | ->setUseCacheHash(FALSE) |
||
| 90 | //->setNoCache(TRUE) |
||
| 91 | ->buildFrontendUri(); |
||
| 92 | |||
| 93 | $additionalGetVars = $this->uriBuilder |
||
| 94 | ->reset() |
||
| 95 | ->setTargetPageUid($pageUid) |
||
| 96 | ->setUseCacheHash(TRUE) |
||
| 97 | //->setNoCache(TRUE) |
||
| 98 | ->setArguments( |
||
| 99 | array( 'tx_dlf' => array( |
||
| 100 | 'id' => urldecode($previewMets), |
||
| 101 | ) |
||
| 102 | ) |
||
| 103 | ) |
||
| 104 | ->setCreateAbsoluteUri(true) |
||
| 105 | ->buildFrontendUri(); |
||
| 106 | |||
| 107 | $title = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('manager.tooltip.preview', 'dpf', $arguments = null); |
||
| 108 | $icon = '<a href="'. $additionalGetVars . '" data-toggle="tooltip" class="' . $class . '" title="' . $title . '">' . $insideText . '</a>'; |
||
| 109 | |||
| 110 | return $icon; |
||
| 111 | |||
| 112 | } |
||
| 113 | |||
| 114 | public function initializeArguments() |
||
| 115 | { |
||
| 116 | parent::initializeArguments(); |
||
| 117 | |||
| 118 | $this->registerArgument('arguments', 'array', '', true); |
||
| 119 | $this->registerArgument('pageUid', 'int', '', true); |
||
| 120 | $this->registerArgument('apiPid', 'int', '', true); |
||
| 121 | $this->registerArgument('class', 'string', '', true); |
||
| 122 | } |
||
| 123 | |||
| 124 | /** |
||
| 125 | * Renders a record list as known from the TYPO3 list module |
||
| 126 | * Note: This feature is experimental! |
||
| 127 | * |
||
| 128 | * @return string the rendered record list |
||
| 129 | */ |
||
| 130 | public function render() |
||
| 131 | { |
||
| 132 | $arguments = $this->arguments['arguments']; |
||
| 133 | $pageUid = $this->arguments['pageUid']; |
||
| 134 | $apiPid = $this->arguments['apiPid']; |
||
| 135 | $class = $this->arguments['class']; |
||
| 136 | |||
| 137 | if ($arguments['document']) { |
||
| 138 | |||
| 139 | // it's already a document object? |
||
| 140 | if ($arguments['document'] instanceof \EWW\Dpf\Domain\Model\Document) { |
||
| 141 | |||
| 142 | $document = $arguments['document']; |
||
| 143 | |||
| 144 | } else if (MathUtility::canBeInterpretedAsInteger($arguments['document'])) { |
||
| 145 | |||
| 146 | $document = $this->documentRepository->findByUid($arguments['document']); |
||
| 147 | |||
| 148 | } |
||
| 149 | |||
| 150 | // we found a valid document |
||
| 151 | if ($document) { |
||
|
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
Loading history...
|
|||
| 152 | |||
| 153 | $row['qid'] = $document->getUid(); |
||
|
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||
| 154 | |||
| 155 | $row['action'] = 'preview'; |
||
| 156 | |||
| 157 | } else { |
||
| 158 | |||
| 159 | // ok, nothing to render. So return empty content. |
||
| 160 | return ''; |
||
| 161 | |||
| 162 | } |
||
| 163 | |||
| 164 | } else if ($arguments['documentObjectIdentifier']) { |
||
| 165 | |||
| 166 | $row['action'] = 'mets'; |
||
| 167 | |||
| 168 | $row['qid'] = $arguments['documentObjectIdentifier']; |
||
| 169 | |||
| 170 | // pass configured API secret key parameter to enable dissemination of inactive documents |
||
| 171 | if (isset($this->secretKey)) { |
||
| 172 | $row['deliverInactive'] = $this->secretKey; |
||
| 173 | } |
||
| 174 | |||
| 175 | } |
||
| 176 | |||
| 177 | $insideText = $this->renderChildren(); |
||
| 178 | |||
| 179 | $content = $this->getViewIcon($row, $pageUid, $apiPid, $insideText, $class); |
||
|
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||
| 180 | |||
| 181 | return $content; |
||
| 182 | |||
| 183 | } |
||
| 184 | } |
||
| 185 |