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.

Revisions

  1. Schweriner revised this gist Mar 20, 2019. 1 changed file with 0 additions and 5 deletions.
    5 changes: 0 additions & 5 deletions EditLinkViewHelper.php
    Original file line number Diff line number Diff line change
    @@ -16,7 +16,6 @@

    use TYPO3\CMS\Backend\Utility\BackendUtility;
    use TYPO3\CMS\Core\Utility\GeneralUtility;
    use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;

    /**
    * ViewHelper to create a link to edit a note
    @@ -41,10 +40,6 @@ public function initializeArguments()
    }

    /**
    * @param array $arguments
    * @param \Closure $renderChildrenClosure
    * @param RenderingContextInterface $renderingContext
    *
    * @return string
    */
    public function render()
  2. Schweriner created this gist Mar 20, 2019.
    64 changes: 64 additions & 0 deletions EditLinkViewHelper.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,64 @@
    <?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;
    use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;

    /**
    * 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);
    }

    /**
    * @param array $arguments
    * @param \Closure $renderChildrenClosure
    * @param RenderingContextInterface $renderingContext
    *
    * @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();
    }

    }