LinkViewHelper für das Backend


LinkViewHelper.php

<?php
namespace Werkraum\WrDailyBulletin\ViewHelpers\Be;

/***************************************************************
 *  Copyright notice
 *
 *  (c) 2015 werkraum GmbH
 *  Eugen Lang <eugen.lang@werkraum.net>
 *
 *  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 3 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 \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractTagBasedViewHelper {

  /**
   * @var string
   */
  protected $tagName = 'a';

  /**
   * Initialize arguments
   *
   * @return void
   */
  public function initializeArguments() {
    $this->registerUniversalTagAttributes();
    $this->registerTagAttribute('name', 'string', 'Specifies the name of an anchor');
    $this->registerTagAttribute('target', 'string', 'Specifies where to open the linked document');
  }

  /**
   * create a link to edit a record
   *
   * @param string $parameters Query string parameters
   * @param string $returnUrl URL to return to
   * @return string The <a> tag
   */
  public function render($parameters, $returnUrl = '') {
    $uri = 'alt_doc.php?' . $parameters;
    if (!empty($returnUrl)) {
      $uri .= '&returnUrl=' . rawurlencode($returnUrl);
    } else {
      $returnUrl = 'mod.php?M='.$_GET['M'].'&moduleToken='.$_GET['moduleToken'];
      $uri .= '&returnUrl=' . rawurlencode($returnUrl);
    }

    $this->tag->addAttribute('href', $uri);
    $this->tag->setContent($this->renderChildren());
    $this->tag->forceClosingTag(TRUE);
    return $this->tag->render();
  }
}

Fluid-Template

{namespace wrd=Werkraum\WrDailyBulletin\ViewHelpers}

<wrd:be.link parameters="edit[tx_wrdailybulletin_domain_model_newsbriefing][{newsbriefing.uid}]=edit" title="Newsbriefing Artikel bearbeiten">
    <span class="t3-icon t3-icon-actions t3-icon-actions-document t3-icon-document-open">&nbsp;</span>
</wrd:be.link>

LinkViewHelper.php

<?php
namespace Werkraum\WrOrganigramm\ViewHelpers\Be;

    /***************************************************************
     *  Copyright notice
     *
     *  (c) 2016 werkraum GmbH
     *  Eugen Lang <eugen.lang@werkraum.net>
     *
     *  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 3 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 \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractTagBasedViewHelper {

    /**
     * @var string
     */
    protected $tagName = 'a';

    /**
     * Initialize arguments
     *
     * @return void
     */
    public function initializeArguments() {
        $this->registerUniversalTagAttributes();
        $this->registerTagAttribute('name', 'string', 'Specifies the name of an anchor');
        $this->registerTagAttribute('target', 'string', 'Specifies where to open the linked document');
    }

    /**
     * create a link to edit a record
     *
     * @param string $parameters Query string parameters
     * @param string $returnUrl URL to return to
     * @return string The <a> tag
     */
    public function render($parameters, $returnUrl = '') {
        $uri = \TYPO3\CMS\Backend\Utility\BackendUtility::getModuleUrl('record_edit').'&'.$parameters;
        if (!empty($returnUrl)) {
            $uri .= '&returnUrl='.rawurlencode($returnUrl);
        } else {
            $uri .= '&returnUrl='.rawurlencode(\TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('REQUEST_URI'));
        }
        $this->tag->addAttribute('href', $uri);
        $this->tag->setContent($this->renderChildren());
        $this->tag->forceClosingTag(TRUE);
        return $this->tag->render();
    }
}

Fluid-Template

{namespace wr=Werkraum\WrOrganigramm\ViewHelpers}

<wr:be.link parameters="edit[{model}][{id}]=edit"
            title="Datensatz bearbeiten" data="{original-title:'Datensatz bearbeiten'}"><i class="fa fa-pencil"></i>
</wr:be.link>

Ab einer gewissen Projektgröße kommen meist auch individuelle Backend-Module zum Einsatz, die es erlauben Datensätze einzusehen, anzulegen oder zu bearbeiten. Damit man aus dem eigenen Backend-Modul in einen Datensatz hineinspringen kann und beim "speichern und schließen" wieder zurück in das Backend-Modul kommt, muss ein entsprechender Link generiert werden.

In TYPO3 6.2 sah das dann so aus:

 

Seit TYPO3 7.5 sieht das nun etwas anders aus:

Kategorien

  Devblog

Hat dir der Artikel gefallen?

Werkraum News: