|
| 1 | +<?php |
| 2 | +declare(strict_types=1); |
| 3 | +namespace Helhum\TyposcriptRendering\ViewHelpers\Uri; |
| 4 | + |
| 5 | +/* |
| 6 | + * This file is part of the TypoScript Rendering TYPO3 extension. |
| 7 | + * |
| 8 | + * It is free software; you can redistribute it and/or modify it under |
| 9 | + * the terms of the GNU General Public License, either version 2 |
| 10 | + * of the License, or any later version. |
| 11 | + * |
| 12 | + * For the full copyright and license information, please read |
| 13 | + * LICENSE file that was distributed with this source code. |
| 14 | + * |
| 15 | + */ |
| 16 | + |
| 17 | +use Helhum\TyposcriptRendering\Uri\TyposcriptRenderingUri; |
| 18 | +use Helhum\TyposcriptRendering\Uri\ViewHelperContext; |
| 19 | +use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractTagBasedViewHelper; |
| 20 | + |
| 21 | +/** |
| 22 | + * A view helper for creating links to extbase actions. |
| 23 | + * |
| 24 | + * = Examples = |
| 25 | + * |
| 26 | + * <code title="link to the show-action of the current controller"> |
| 27 | + * <t:link.action action="show">action link</f:link.action> |
| 28 | + * </code> |
| 29 | + * <output> |
| 30 | + * <a href="index.php?id=123&tx_typoscriptrendering[context]={"record":"tt_content_123","path":"tt_content.list.20.myextension_plugin"}&tx_myextension_plugin[action]=show&tx_myextension_plugin[controller]=Standard&cHash=xyz">action link</f:link.action> |
| 31 | + * (depending on the current page and your TS configuration) |
| 32 | + * </output> |
| 33 | + */ |
| 34 | +class ActionViewHelper extends AbstractTagBasedViewHelper |
| 35 | +{ |
| 36 | + /** |
| 37 | + * @var string |
| 38 | + */ |
| 39 | + protected $tagName = 'a'; |
| 40 | + |
| 41 | + /** |
| 42 | + * Arguments initialization |
| 43 | + */ |
| 44 | + public function initializeArguments() |
| 45 | + { |
| 46 | + parent::initializeArguments(); |
| 47 | + $this->registerUniversalTagAttributes(); |
| 48 | + $this->registerTagAttribute('name', 'string', 'Specifies the name of an anchor'); |
| 49 | + $this->registerTagAttribute('rel', 'string', 'Specifies the relationship between the current document and the linked document'); |
| 50 | + $this->registerTagAttribute('rev', 'string', 'Specifies the relationship between the linked document and the current document'); |
| 51 | + $this->registerTagAttribute('target', 'string', 'Specifies where to open the linked document'); |
| 52 | + $this->registerArgument('action', 'string', 'Target action'); |
| 53 | + $this->registerArgument('arguments', 'array', 'Arguments for the controller action, associative array', false, []); |
| 54 | + $this->registerArgument('controller', 'string', 'Target controller. If NULL current controllerName is used'); |
| 55 | + $this->registerArgument('extensionName', 'string', 'Target Extension Name (without "tx_" prefix and no underscores). If NULL the current extension name is used'); |
| 56 | + $this->registerArgument('pluginName', 'string', 'Target plugin. If empty, the current plugin name is used'); |
| 57 | + $this->registerArgument('pageUid', 'int', 'Target page. See TypoLink destination'); |
| 58 | + $this->registerArgument('pageType', 'int', 'Type of the target page. See typolink.parameter', false, 0); |
| 59 | + $this->registerArgument('noCache', 'bool', 'Set this to disable caching for the target page. You should not need this.', false, false); |
| 60 | + $this->registerArgument('section', 'string', 'The anchor to be added to the URI', false, ''); |
| 61 | + $this->registerArgument('format', 'string', 'The requested format, e.g. ".html', false, ''); |
| 62 | + $this->registerArgument('linkAccessRestrictedPages', 'bool', 'If set, links pointing to access restricted pages will still link to the page even though the page cannot be accessed.', false, false); |
| 63 | + $this->registerArgument('additionalParams', 'array', 'Additional query parameters that won\'t be prefixed like $arguments (overrule $arguments)', false, []); |
| 64 | + $this->registerArgument('absolute', 'bool', 'If set, the URI of the rendered link is absolute', false, false); |
| 65 | + $this->registerArgument('addQueryString', 'bool', 'If set, the current query parameters will be kept in the URI', false, false); |
| 66 | + $this->registerArgument('argumentsToBeExcludedFromQueryString', 'array', 'Arguments to be removed from the URI. Only active if $addQueryString = TRUE', false, []); |
| 67 | + $this->registerArgument('addQueryStringMethod', 'string', 'Set which parameters will be kept. Only active if $addQueryString = TRUE'); |
| 68 | + $this->registerArgument('contextRecord', 'string', 'The record that the rendering should depend upon. e.g. current (default: record is fetched from current Extbase plugin), tt_content:12 (tt_content record with uid 12), pages:15 (pages record with uid 15), \'currentPage\' record of current page', false, 'current'); |
| 69 | + } |
| 70 | + |
| 71 | + /** |
| 72 | + * @return string Rendered link |
| 73 | + */ |
| 74 | + public function render() |
| 75 | + { |
| 76 | + $uri = (new TyposcriptRenderingUri())->withViewHelperContext( |
| 77 | + new ViewHelperContext( |
| 78 | + $this->renderingContext, |
| 79 | + $this->arguments |
| 80 | + ) |
| 81 | + ); |
| 82 | + |
| 83 | + $this->tag->addAttribute('href', $uri); |
| 84 | + $this->tag->setContent($this->renderChildren()); |
| 85 | + $this->tag->forceClosingTag(true); |
| 86 | + |
| 87 | + return $this->tag->render(); |
| 88 | + } |
| 89 | +} |
0 commit comments