Skip to content
Snippets Groups Projects
EditOnClickViewHelper.php 2.38 KiB
Newer Older
<?php

namespace SGalinski\SgNews\ViewHelpers\Backend;

/***************************************************************
 *  Copyright notice
 *
 *  (c) sgalinski Internet Services (https://www.sgalinski.de)
 *
 *  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!
 ***************************************************************/

use SGalinski\SgNews\Utility\BackendNewsUtility;
Paul Ilea's avatar
Paul Ilea committed
use SGalinski\SgNews\ViewHelpers\AbstractViewHelper;
use TYPO3\CMS\Backend\Utility\BackendUtility;

/**
 * Class EditOnClickViewHelper
 **/
class EditOnClickViewHelper extends AbstractViewHelper {

	/**
	 * Register the ViewHelper arguments
	 */
	public function initializeArguments() {
		parent::initializeArguments();
		$this->registerArgument('table', 'string', 'The table for the clickenlarge link', TRUE);
		$this->registerArgument('uid', 'int', 'The uid of the record to clickenlarge', TRUE);
		$this->registerArgument('new', 'bool', 'Open a new record in the popup', FALSE, FALSE);
		$this->registerArgument('type', 'string', 'The type of the news', FALSE, '');
	}

	/**
	 * Renders the onclick script for editing a record
	 *
	 * @return string
	 */
	public function render(): string {
		$table = $this->arguments['table'];
		$uid = $this->arguments['uid'];
		$new = $this->arguments['new'];
		$type = $this->arguments['type'];
Paul Ilea's avatar
Paul Ilea committed
		$additionalParameters = '';
		if ($new && $table === 'pages' && in_array($type, ['news', 'category'], TRUE)) {
			$additionalParameters = '&overrideVals[pages][doktype]=' .
				($type === 'news' ? BackendNewsUtility::NEWS_DOKTYPE : BackendNewsUtility::CATEGORY_DOKTYPE);
		}
Paul Ilea's avatar
Paul Ilea committed
		return BackendUtility::editOnClick(
			'&edit[' . $table . '][' . $uid . ']=' . ($new ? 'new' : 'edit') . $additionalParameters, '', -1
		);