LinkViewHelper für das Backend
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:
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"> </span>
</wrd:be.link>
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>
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();
}
}
Hat dir der Artikel gefallen?
Werkraum News:

Wie füge ich CKEditor5 Plugins in TYPO3 12 ein?
Integriere mühelos CKEditor5-Plugins in TYPO3 12! Unser Teaser bietet einen kurzen Einblick, wie du die Vielseitigkeit des CKeditors optimierst und deine Textbearbeitung auf…

Der Schlüssel zur Lesbarkeit: Responsive Font Sizes
Im Dschungel der Internetseiten kann es frustrierend sein, wenn die Schriftgröße nicht mitspielt. Aber keine Sorge, Responsive Font Sizes sind hier, um sicherzustellen, dass…

Einblicke in das Logging-System von TYPO3 und Konfiguration von Log Writern
Tauche ein in die Welt des TYPO3-Loggings! Unser neuester Beitrag zeigt dir nicht nur, wie du das Logging-System optimal konfigurierst, sondern liefert auch Code-Beispiele für…