Skip to content

Instantly share code, notes, and snippets.

@Schweriner
Last active March 20, 2019 12:21
Show Gist options
  • Save Schweriner/0db56a12cffe0448714d7b1ab05ceb6b to your computer and use it in GitHub Desktop.
Save Schweriner/0db56a12cffe0448714d7b1ab05ceb6b to your computer and use it in GitHub Desktop.
TYPO3 Fluid ViewHelper for creating Backend Edit Links for every Record
<?php
namespace Vendor\YourExt\ViewHelpers;
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
/**
* ViewHelper to create a link to edit a note
* @internal
*/
class EditLinkViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractTagBasedViewHelper
{
/**
* @var string
*/
protected $tagName = 'a';
/**
* Initializes the arguments
*/
public function initializeArguments()
{
parent::initializeArguments();
$this->registerUniversalTagAttributes();
$this->registerArgument('uid', 'int', 'The record uid to edit', true);
$this->registerArgument('table', 'string', 'The table to edit', true);
}
/**
* @return string
*/
public function render()
{
$this->tag->addAttribute('href',BackendUtility::getModuleUrl(
'record_edit',
[
'edit[' . $this->arguments['table'] . '][' . $this->arguments['uid'] . ']' => 'edit',
'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
]
));
$this->tag->setContent($this->renderChildren());
$this->tag->forceClosingTag(true);
return $this->tag->render();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment