Skip to content

Instantly share code, notes, and snippets.

@Xatenev
Created November 6, 2014 10:58
Show Gist options
  • Save Xatenev/cf46788808fce511ad3c to your computer and use it in GitHub Desktop.
Save Xatenev/cf46788808fce511ad3c to your computer and use it in GitHub Desktop.
Link View Helper to create edit + new buttons in t3 backend module
<?php
namespace Vendor\Ext\ViewHelpers\Form;
use Vendor\Ext\ViewHelpers\Misc\RequestViewHelper;
use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper;
use TYPO3\CMS\Fluid\Core\ViewHelper\TagBuilder;
/***************************************************************
* Copyright notice
*
* (c) 2014 Johannes Hertenstein
*
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
* ************************************************************* */
class LinkViewHelper extends AbstractViewHelper {
/**
* @var TagBuilder
*/
protected $tag = NULL;
/**
* @param string $to
* @param string $column
* @param integer $uid
*
* @return mixed
*/
public function render($to, $column, $uid = NULL) {
$pid = new RequestViewHelper();
$pid = $pid->render("id");
$this->tag = new TagBuilder("a");
$this->tag->addAttribute("href","#");
$this->tag->setContent($this->renderChildren());
$this->tag->forceClosingTag(TRUE);
$parameter = array();
switch($to){
case "edit":
$parameter[] = "edit[$column][{$uid}]=edit";
break;
case "new":
$parameter[] = "edit[$column][{$pid}]=new";
break;
}
$this->tag->addAttribute("href","alt_doc.php?".implode("&",$parameter));
return $this->tag->render();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment