[TASK] Replace editOnClick() with getModuleUrl 28/43328/4
authorBenjamin Mack <benni@typo3.org>
Tue, 15 Sep 2015 12:29:24 +0000 (14:29 +0200)
committerAnja Leichsenring <aleichsenring@ab-softlab.de>
Wed, 16 Sep 2015 19:38:49 +0000 (21:38 +0200)
The editOnClick produces JS which is not needed in most cases.

Using BackendUtility::getModuleUrl() allows to avoid inline JS code.

Resolves: #69825
Releases: master
Change-Id: I95b69db93d5553eb2998bcbca463f58faec7b18e
Reviewed-on: http://review.typo3.org/43328
Reviewed-by: Georg Ringer <georg.ringer@gmail.com>
Tested-by: Georg Ringer <georg.ringer@gmail.com>
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
typo3/sysext/backend/Classes/Controller/ContentElement/ElementInformationController.php
typo3/sysext/backend/Classes/Controller/NewRecordController.php
typo3/sysext/filelist/Classes/FileList.php
typo3/sysext/info_pagetsconfig/Classes/Controller/InfoPageTyposcriptConfigController.php
typo3/sysext/tstemplate/Classes/Controller/TypoScriptTemplateInformationModuleFunctionController.php

index 287649a..de82966 100644 (file)
@@ -579,25 +579,28 @@ class ElementInformationController {
                }
 
                // Edit button
-               $editOnClick = BackendUtility::editOnClick('&edit[' . $table . '][' . $uid . ']=edit');
+               $urlParameters = [
+                       'edit' => [
+                               $table => [
+                                       $uid => 'edit'
+                               ]
+                       ],
+                       'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
+               ];
+               $url = BackendUtility::getModuleUrl('record_edit', $urlParameters);
                $pageActionIcons = '
-                       <a class="btn btn-default btn-sm" href="#" onclick="' . htmlspecialchars($editOnClick) . '">
+                       <a class="btn btn-default btn-sm" href="' . htmlspecialchars($url) . '">
                                ' . $this->iconFactory->getIcon('actions-document-open', Icon::SIZE_SMALL) . '
                        </a>';
 
                // History button
-               $historyOnClick = 'window.location.href=' .
-                       GeneralUtility::quoteJSvalue(
-                               BackendUtility::getModuleUrl(
-                                       'record_history',
-                                       array(
-                                               'element' => $table . ':' . $uid,
-                                               'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
-                                       )
-                               )
-                       ) . '; return false;';
+               $urlParameters = [
+                       'element' => $table . ':' . $uid,
+                       'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
+               ];
+               $url = BackendUtility::getModuleUrl('record_history', $urlParameters);
                $pageActionIcons .= '
-                       <a class="btn btn-default btn-sm" href="#" onclick="' . htmlspecialchars($historyOnClick) . '">
+                       <a class="btn btn-default btn-sm" href="' . htmlspecialchars($url) . '">
                                ' . $this->iconFactory->getIcon('actions-document-history-open', Icon::SIZE_SMALL) . '
                        </a>';
 
@@ -678,16 +681,24 @@ class ElementInformationController {
                                        : '';
                                $icon = IconUtility::getSpriteIconForRecord($row['tablename'], $record);
                                $actions = $this->getRecordActions($row['tablename'], $row['recuid']);
-                               $editOnClick = BackendUtility::editOnClick('&edit[' . $row['tablename'] . '][' . $row['recuid'] . ']=edit');
+                               $urlParameters = [
+                                       'edit' => [
+                                               $row['tablename'] => [
+                                                       $row['recuid'] => 'edit'
+                                               ]
+                                       ],
+                                       'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
+                               ];
+                               $url = BackendUtility::getModuleUrl('record_edit', $urlParameters);
                                $infoData[] = '
                                <tr>
                                        <td class="col-icon">
-                                               <a href="#" onclick="' . htmlspecialchars($editOnClick) . '" title="id=' . $record['uid'] . '">
+                                               <a href="' . htmlspecialchars($url) . '" title="id=' . $record['uid'] . '">
                                                        ' . $icon . '
                                                </a>
                                        </td>
                                        <td class="col-title">
-                                               <a href="#" onclick="' . htmlspecialchars($editOnClick) . '" title="id=' . $record['uid'] . '" >
+                                               <a href="' . htmlspecialchars($url) . '" title="id=' . $record['uid'] . '" >
                                                        ' . BackendUtility::getRecordTitle($row['tablename'], $record, TRUE) . '
                                                </a>
                                        </td>
@@ -770,16 +781,25 @@ class ElementInformationController {
                        if ($record) {
                                $icon = IconUtility::getSpriteIconForRecord($row['tablename'], $record);
                                $actions = $this->getRecordActions($row['ref_table'], $row['ref_uid']);
-                               $editOnClick = BackendUtility::editOnClick('&edit[' . $row['ref_table'] . '][' . $row['ref_uid'] . ']=edit');
+
+                               $urlParameters = [
+                                       'edit' => [
+                                               $row['ref_table'] => [
+                                                       $row['ref_uid'] => 'edit'
+                                               ]
+                                       ],
+                                       'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
+                               ];
+                               $url = BackendUtility::getModuleUrl('record_edit', $urlParameters);
                                $infoData[] = '
                                <tr>
                                        <td class="col-icon">
-                                               <a href="#" onclick="' . htmlspecialchars($editOnClick) . '" title="id=' . $record['uid'] . '">
+                                               <a href="' . htmlspecialchars($url) . '" title="id=' . $record['uid'] . '">
                                                        ' . $icon . '
                                                </a>
                                        </td>
                                        <td class="col-title">
-                                               <a href="#" onclick="' . htmlspecialchars($editOnClick) . '" title="id=' . $record['uid'] . '" >
+                                               <a href="' . htmlspecialchars($url) . '" title="id=' . $record['uid'] . '" >
                                                        ' . BackendUtility::getRecordTitle($row['ref_table'], $record, TRUE) . '
                                                </a>
                                        </td>
index 596380a..b53f520 100644 (file)
@@ -361,10 +361,16 @@ class NewRecordController {
                        $this->code .= $positionMap->positionTree($this->id, $this->pageinfo, $this->perms_clause, $this->R_URI);
                } else {
                        // No pages yet, no need to prompt for position, redirect to page creation.
-                       $javascript = stripslashes(BackendUtility::editOnClick('&edit[pages][0]=new&returnNewPageId=1', '', BackendUtility::getModuleUrl('db_new', array('id' => $this->id, 'pagesOnly' => '1'))));
-                       $startPos = strpos($javascript, 'href=\'') + 6;
-                       $endPos = strpos($javascript, '\';');
-                       $url = substr($javascript, $startPos, $endPos - $startPos);
+                       $urlParameters = [
+                               'edit' => [
+                                       'pages' => [
+                                               0 => 'new'
+                                       ]
+                               ],
+                               'returnNewPageId' => 1,
+                               'returnUrl' => BackendUtility::getModuleUrl('db_new', array('id' => $this->id, 'pagesOnly' => '1'))
+                       ];
+                       $url = BackendUtility::getModuleUrl('record_edit', $urlParameters);
                        @ob_end_clean();
                        HttpUtility::redirect($url);
                }
@@ -588,14 +594,22 @@ class NewRecordController {
         * @return string The link.
         */
        public function linkWrap($linkText, $table, $pid, $addContentTable = FALSE) {
-               $parameters = '&edit[' . $table . '][' . $pid . ']=new';
+               $urlParameters = [
+                       'edit' => [
+                               $table => [
+                                       $pid => 'new'
+                               ]
+                       ],
+                       'returnUrl' => $this->returnUrl
+               ];
                if ($table == 'pages' && $addContentTable) {
-                       $parameters .= '&edit[tt_content][prev]=new&returnNewPageId=1';
+                       $urlParameters['tt_content']['prev'] = 'new';
+                       $urlParameters['returnNewPageId'] = 1;
                } elseif ($table == 'pages_language_overlay') {
-                       $parameters .= '&overrideVals[pages_language_overlay][doktype]=' . (int)$this->pageinfo['doktype'];
+                       $urlParameters['overrideVals']['pages_language_overlay']['doktype'] = (int)$this->pageinfo['doktype'];
                }
-               $onClick = BackendUtility::editOnClick($parameters, '', $this->returnUrl);
-               return '<a href="#" onclick="' . htmlspecialchars($onClick) . '">' . $linkText . '</a>';
+               $url = BackendUtility::getModuleUrl('record_edit', $urlParameters);
+               return '<a href="' . htmlspecialchars($url) . '">' . $linkText . '</a>';
        }
 
        /**
index a8c2d1a..cce7e53 100644 (file)
@@ -604,12 +604,17 @@ class FileList extends AbstractRecordList {
                try {
                        if ($fileObject instanceof File && $fileObject->isIndexed() && $fileObject->checkActionPermission('write') && $this->getBackendUser()->check('tables_modify', 'sys_file_metadata')) {
                                $metaData = $fileObject->_getMetaData();
-                               $data = array(
-                                       'sys_file_metadata' => array($metaData['uid'] => 'edit')
-                               );
-                               $editOnClick = BackendUtility::editOnClick(GeneralUtility::implodeArrayForUrl('edit', $data), '', $this->listUrl());
+                               $urlParameters = [
+                                       'edit' => [
+                                               'sys_file_metadata' => [
+                                                       $metaData['uid'] => 'edit'
+                                               ]
+                                       ],
+                                       'returnUrl' => $this->listURL()
+                               ];
+                               $url = BackendUtility::getModuleUrl('record_edit', $urlParameters);
                                $title = htmlspecialchars($this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:cm.editMetadata'));
-                               $code = '<a href="#" title="' . $title . '" onclick="' . htmlspecialchars($editOnClick) . '">' . GeneralUtility::fixed_lgd_cs($code, $this->fixedL) . '</a>';
+                               $code = '<a href="' . htmlspecialchars($url) . '" title="' . $title . '">' . GeneralUtility::fixed_lgd_cs($code, $this->fixedL) . '</a>';
                        }
                } catch (\Exception $e) {
                        // intentional fall-through
@@ -696,12 +701,17 @@ class FileList extends AbstractRecordList {
                                                                        $title = htmlspecialchars(sprintf($GLOBALS['LANG']->getLL('editMetadataForLanguage'), $language['title']));
                                                                        // @todo the overlay for the flag needs to be added ($flagIcon . '-overlay')
                                                                        $flagButtonIcon = $this->iconFactory->getIcon('actions-document-open', Icon::SIZE_SMALL);
-                                                                       $data = array(
-                                                                               'sys_file_metadata' => array($translations[$languageId]['uid'] => 'edit')
-                                                                       );
-                                                                       $editOnClick = BackendUtility::editOnClick(GeneralUtility::implodeArrayForUrl('edit', $data), '', $this->listUrl());
-                                                                       $languageCode .= '<a href="#" class="btn btn-default" onclick="'
-                                                                               . htmlspecialchars($editOnClick) . '" title="' . $title . '">'
+                                                                       $urlParameters = [
+                                                                               'edit' => [
+                                                                                       'sys_file_metadata' => [
+                                                                                               $translations[$languageId]['uid'] => 'edit'
+                                                                                       ]
+                                                                               ],
+                                                                               'returnUrl' => $this->listURL()
+                                                                       ];
+                                                                       $url = BackendUtility::getModuleUrl('record_edit', $urlParameters);
+                                                                       $languageCode .= '<a href="' . htmlspecialchars($url)
+                                                                               . '" class="btn btn-default" title="' . $title . '">'
                                                                                . $flagButtonIcon . '</a>';
                                                                } else {
                                                                        $parameters = [
index 5fce09d..f7dd4ba 100644 (file)
@@ -115,9 +115,17 @@ class InfoPageTyposcriptConfigController extends \TYPO3\CMS\Backend\Module\Abstr
                                                        $row = BackendUtility::getRecordWSOL('pages', substr($k, 4));
                                                        $pTitle = $this->pObj->doc->getHeader('pages', $row, '', FALSE);
                                                        $editIdList = substr($k, 4);
-                                                       $params = '&edit[pages][' . $editIdList . ']=edit&columnsOnly=TSconfig';
-                                                       $onclickUrl = BackendUtility::editOnClick($params);
-                                                       $editIcon = '<a href="#" onclick="' . htmlspecialchars($onclickUrl) . '" title="' . $this->getLanguageService()->getLL('editTSconfig', TRUE) . '">' . $this->iconFactory->getIcon('actions-document-open', Icon::SIZE_SMALL) . '</a>';
+                                                       $urlParameters = [
+                                                               'edit' => [
+                                                                       'pages' => [
+                                                                               $editIdList => 'edit',
+                                                                       ]
+                                                               ],
+                                                               'columnsOnly' => 'TSconfig',
+                                                               'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
+                                                       ];
+                                                       $url = BackendUtility::getModuleUrl('record_edit', $urlParameters);
+                                                       $editIcon = '<a href="' . htmlspecialchars($url) . '" title="' . $this->getLanguageService()->getLL('editTSconfig', TRUE) . '">' . $this->iconFactory->getIcon('actions-document-open', Icon::SIZE_SMALL) . '</a>';
                                                }
                                                $TScontent = nl2br(htmlspecialchars(trim($v) . LF));
                                                $tsparser = GeneralUtility::makeInstance(\TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser::class);
@@ -131,9 +139,17 @@ class InfoPageTyposcriptConfigController extends \TYPO3\CMS\Backend\Module\Abstr
                                        }
                                }
                                if (!empty($pUids)) {
-                                       $params = '&edit[pages][' . implode(',', $pUids) . ']=edit&columnsOnly=TSconfig';
-                                       $onclickUrl = BackendUtility::editOnClick($params);
-                                       $editIcon = '<a href="#" onclick="' . htmlspecialchars($onclickUrl) . '" title="' . $this->getLanguageService()->getLL('editTSconfig_all', TRUE) . '">' . $this->iconFactory->getIcon('actions-document-open', Icon::SIZE_SMALL) . '<strong>' . $this->getLanguageService()->getLL('editTSconfig_all', TRUE) . '</strong>' . '</a>';
+                                       $urlParameters = [
+                                               'edit' => [
+                                                       'pages' => [
+                                                               implode(',', $pUids) => 'edit',
+                                                       ]
+                                               ],
+                                               'columnsOnly' => 'TSconfig',
+                                               'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
+                                       ];
+                                       $url = BackendUtility::getModuleUrl('record_edit', $urlParameters);
+                                       $editIcon = '<a href="' . htmlspecialchars($url) . '" title="' . $this->getLanguageService()->getLL('editTSconfig_all', TRUE) . '">' . $this->iconFactory->getIcon('actions-document-open', Icon::SIZE_SMALL) . '<strong>' . $this->getLanguageService()->getLL('editTSconfig_all', TRUE) . '</strong>' . '</a>';
                                } else {
                                        $editIcon = '';
                                }
index b8c76bc..3912a70 100644 (file)
@@ -67,20 +67,31 @@ class TypoScriptTemplateInformationModuleFunctionController extends AbstractFunc
         */
        public function tableRow($label, $data, $field, $id) {
                $lang = $this->getLanguageService();
-               $ret = '<tr><td>';
-               $title = $lang->sL('LLL:EXT:lang/locallang_common.xlf:editField', TRUE);
                if ($field === 'config' || $field === 'constants') {
-                       $urlParameters = array(
-                               'id' => $this->pObj->id
-                       );
-                       $aHref = BackendUtility::getModuleUrl('web_ts', $urlParameters);
-                       $startAnchor = '<a href="' . htmlspecialchars(($aHref . '&e[' . $field . ']=1')) . '" title="' . $title . '">';
+                       $urlParameters = [
+                               'id' => $this->pObj->id,
+                               'e' => [
+                                       $field => 1
+                               ]
+                       ];
+                       $url = BackendUtility::getModuleUrl('web_ts', $urlParameters);
                } else {
-                       $params = '&columnsOnly=' . $field . '&createExtension=0' . '&edit[sys_template][' . $id . ']=edit';
-                       $editOnClick = BackendUtility::editOnClick($params);
-                       $startAnchor = '<a href="#" onclick="' . htmlspecialchars($editOnClick) . '" title="' . $title . '">';
+                       $urlParameters = [
+                               'edit' => [
+                                       'sys_template' => [
+                                               $id => 'edit'
+                                       ]
+                               ],
+                               'columnsOnly' => $field,
+                               'createExtension' => 0,
+                               'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
+                       ];
+                       $url = BackendUtility::getModuleUrl('record_edit', $urlParameters);
                }
+               $title = $lang->sL('LLL:EXT:lang/locallang_common.xlf:editField', TRUE);
+               $startAnchor = '<a href="' . htmlspecialchars($url) . '" title="' . $title . '">';
                $icon = $this->iconFactory->getIcon('actions-document-open', Icon::SIZE_SMALL);
+               $ret = '<tr><td>';
                $ret .= $startAnchor . '<strong>' . $label . '</strong></a>';
                $ret .= '</td><td width="80%">' . $data . '</td><td>' . $startAnchor . '<span class="btn btn-default">' . $icon . '</span></a></td></tr>';
                return $ret;
@@ -178,12 +189,12 @@ class TypoScriptTemplateInformationModuleFunctionController extends AbstractFunc
                $newId = $this->pObj->createTemplate($this->pObj->id, $saveId);
                if ($newId) {
                        // Switch to new template
-                       $urlParameters = array(
+                       $urlParameters = [
                                'id' => $this->pObj->id,
                                'SET[templatesOnPage]' => $newId
-                       );
-                       $aHref = BackendUtility::getModuleUrl('web_ts', $urlParameters);
-                       HttpUtility::redirect($aHref);
+                       ];
+                       $url = BackendUtility::getModuleUrl('web_ts', $urlParameters);
+                       HttpUtility::redirect($url);
                }
                $tce = NULL;
                $theOutput = '';
@@ -283,10 +294,19 @@ class TypoScriptTemplateInformationModuleFunctionController extends AbstractFunc
                        $outCode = '<div class="table-fit"><table class="table table-striped table-hover">' . $outCode . '</table></div>';
 
                        // Edit all icon:
-                       $editOnClick = BackendUtility::editOnClick('&createExtension=0&edit[sys_template][' . $tplRow['uid'] . ']=edit');
+                       $urlParameters = [
+                               'edit' => [
+                                       'sys_template' => [
+                                               $tplRow['uid'] => 'edit'
+                                       ]
+                               ],
+                               'createExtension' => 0,
+                               'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
+                       ];
+                       $url = BackendUtility::getModuleUrl('record_edit', $urlParameters);
                        $title = $lang->getLL('editTemplateRecord', TRUE);
                        $icon = $this->iconFactory->getIcon('actions-document-open', Icon::SIZE_SMALL);
-                       $outCode .= '<br /><a class="btn btn-default" href="#" onclick="' . htmlspecialchars($editOnClick)
+                       $outCode .= '<br /><a class="btn btn-default" href="' . htmlspecialchars($url)
                                . '"><strong>' . $icon . '&nbsp;' . $title . '</strong></a>';
                        $theOutput .= $this->pObj->doc->section('', $outCode);