Commit 3d963ae9 authored by Benni Mack's avatar Benni Mack Committed by Frank Nägler
Browse files

[TASK] Replace editOnClick in Page Layout Module

Replaces all JavaScript code for building URLs
with proper <a href=""> HTML output.

Resolves: #71261
Releases: master
Change-Id: I40b2adc52936cfb8d7d4b0e5f7742d3391ed2a98
Reviewed-on: https://review.typo3.org/44494

Reviewed-by: default avatarMorton Jonuschat <m.jonuschat@mojocode.de>
Tested-by: default avatarMorton Jonuschat <m.jonuschat@mojocode.de>
Reviewed-by: Frank Nägler's avatarFrank Nägler <frank.naegler@typo3.org>
Tested-by: Frank Nägler's avatarFrank Nägler <frank.naegler@typo3.org>
parent f992c575
......@@ -1114,17 +1114,34 @@ class PageLayoutController
'',
''
);
// Edit button
$urlParameters = [
'edit' => [
'pages_language_overlay' => [
$overlayRecord['uid'] => 'edit'
]
],
'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
];
$url = BackendUtility::getModuleUrl('record_edit', $urlParameters);
$editLanguageButton = $this->buttonBar->makeLinkButton()
->setHref('#')
->setHref($url)
->setTitle($lang->getLL('editPageLanguageOverlayProperties'))
->setOnClick(BackendUtility::editOnClick('&edit[pages_language_overlay][' . $overlayRecord['uid'] . ']=edit'))
->setIcon($this->iconFactory->getIcon('mimetypes-x-content-page-language-overlay', Icon::SIZE_SMALL));
$this->buttonBar->addButton($editLanguageButton, ButtonBar::BUTTON_POSITION_LEFT, 3);
}
$urlParameters = [
'edit' => [
'pages' => [
$this->id => 'edit'
]
],
'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
];
$url = BackendUtility::getModuleUrl('record_edit', $urlParameters);
$editPageButton = $this->buttonBar->makeLinkButton()
->setHref('#')
->setHref($url)
->setTitle($lang->getLL('editPageProperties'))
->setOnClick(BackendUtility::editOnClick('&edit[pages][' . $this->id . ']=edit'))
->setIcon($this->iconFactory->getIcon('actions-page-open', Icon::SIZE_SMALL));
$this->buttonBar->addButton($editPageButton, ButtonBar::BUTTON_POSITION_LEFT, 3);
}
......
......@@ -369,12 +369,21 @@ class PageLayoutView extends \TYPO3\CMS\Recordlist\RecordList\AbstractDatabaseRe
// Traverse fields (as set above) in order to create header values:
foreach ($this->fieldArray as $field) {
if ($editIdList && isset($GLOBALS['TCA']['pages']['columns'][$field]) && $field != 'uid' && !$this->pages_noEditColumns) {
$params = '&edit[pages][' . $editIdList . ']=edit&columnsOnly=' . $field;
$iTitle = sprintf(
$this->getLanguageService()->getLL('editThisColumn'),
rtrim(trim($this->getLanguageService()->sL(BackendUtility::getItemLabel('pages', $field))), ':')
);
$eI = '<a href="#" onclick="' . htmlspecialchars(BackendUtility::editOnClick($params))
$urlParameters = [
'edit' => [
'pages' => [
$editIdList => 'edit'
]
],
'columnsOnly' => $field,
'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
];
$url = BackendUtility::getModuleUrl('record_edit', $urlParameters);
$eI = '<a href="' . htmlspecialchars($url)
. '" title="' . htmlspecialchars($iTitle) . '">'
. $this->iconFactory->getIcon('actions-document-open', Icon::SIZE_SMALL)->render() . '</a>';
} else {
......@@ -512,8 +521,35 @@ class PageLayoutView extends \TYPO3\CMS\Recordlist\RecordList\AbstractDatabaseRe
&& $this->getBackendUser()->doesUserHaveAccess($this->pageinfo, Permission::CONTENT_EDIT)
&& (!$this->checkIfTranslationsExistInLanguage($contentRecordsPerColumn, $lP))
) {
$link = '<a href="#" onclick="' . htmlspecialchars($this->newContentElementOnClick($id, $key, $lP))
. '" title="' . $this->getLanguageService()->getLL('newContentElement', true) . '" class="btn btn-default btn-sm">'
if ($this->option_newWizard) {
$urlParameters = [
'id' => $id,
'sys_language_uid' => $lP,
'colPos' => $key,
'uid_pid' => $id,
'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
];
$url = BackendUtility::getModuleUrl('new_content_element', $urlParameters);
} else {
$urlParameters = [
'edit' => [
'tt_content' => [
$id => 'new'
]
],
'defVals' => [
'tt_content' => [
'colPos' => $key,
'sys_language_uid' => $lP
]
],
'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
];
$url = BackendUtility::getModuleUrl('record_edit', $urlParameters);
}
$link = '<a href="' . htmlspecialchars($url) . '" title="'
. $this->getLanguageService()->getLL('newContentElement', true) . '" class="btn btn-default btn-sm">'
. $this->iconFactory->getIcon('actions-document-new', Icon::SIZE_SMALL)->render()
. ' '
. $this->getLanguageService()->getLL('content', true) . '</a>';
......@@ -586,16 +622,27 @@ class PageLayoutView extends \TYPO3\CMS\Recordlist\RecordList\AbstractDatabaseRe
) {
// New content element:
if ($this->option_newWizard) {
$onClick = 'window.location.href=' . GeneralUtility::quoteJSvalue(BackendUtility::getModuleUrl('new_content_element') . '&id=' . $row['pid']
. '&sys_language_uid=' . $row['sys_language_uid'] . '&colPos=' . $row['colPos']
. '&uid_pid=' . -$row['uid'] .
'&returnUrl=' . rawurlencode(GeneralUtility::getIndpEnv('REQUEST_URI'))) . ';';
$urlParameters = [
'id' => $row['pid'],
'sys_language_uid' => $row['sys_language_uid'],
'colPos' => $row['colPos'],
'uid_pid' => -$row['uid'],
'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
];
$url = BackendUtility::getModuleUrl('new_content_element', $urlParameters);
} else {
$params = '&edit[tt_content][' . -$row['uid'] . ']=new';
$onClick = BackendUtility::editOnClick($params);
$urlParameters = [
'edit' => [
'tt_content' => [
-$row['uid'] => 'new'
]
],
'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
];
$url = BackendUtility::getModuleUrl('record_edit', $urlParameters);
}
$singleElementHTML .= '
<a href="#" onclick="' . htmlspecialchars($onClick) . '" title="'
<a href="' . htmlspecialchars($url) . '" title="'
. $this->getLanguageService()->getLL('newContentElement', true) . '" class="btn btn-default btn-sm">'
. $this->iconFactory->getIcon('actions-document-new', Icon::SIZE_SMALL)->render()
. ' '
......@@ -613,8 +660,6 @@ class PageLayoutView extends \TYPO3\CMS\Recordlist\RecordList\AbstractDatabaseRe
}
}
$content[$key] .= '</div>';
// Add new-icon link, header:
$newP = $this->newContentElementOnClick($id, $key, $lP);
$colTitle = BackendUtility::getProcessedValue('tt_content', 'colPos', $key);
$tcaItems = GeneralUtility::callUserFunction(\TYPO3\CMS\Backend\View\BackendLayoutView::class . '->getColPosListItemsParsed', $id, $this);
foreach ($tcaItems as $item) {
......@@ -627,7 +672,7 @@ class PageLayoutView extends \TYPO3\CMS\Recordlist\RecordList\AbstractDatabaseRe
$editParam = $this->doEdit && !empty($rowArr)
? '&edit[tt_content][' . $editUidList . ']=edit' . $pageTitleParamForAltDoc
: '';
$head[$key] .= $this->tt_content_drawColHeader($colTitle, $editParam, $newP, $pasteP);
$head[$key] .= $this->tt_content_drawColHeader($colTitle, $editParam, '', $pasteP);
}
// For each column, fit the rendered content into a table cell:
$out = '';
......@@ -751,9 +796,23 @@ class PageLayoutView extends \TYPO3\CMS\Recordlist\RecordList\AbstractDatabaseRe
'pages_language_overlay',
$lpRecord['uid']
);
$urlParameters = [
'edit' => [
'pages_language_overlay' => [
$lpRecord['uid'] => 'edit'
]
],
'overrideVals' => [
'pages_language_overlay' => [
'sys_language_uid' => $lP
]
],
'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
];
$url = BackendUtility::getModuleUrl('record_edit', $urlParameters);
$editLink = ($this->getBackendUser()->check('tables_modify', 'pages_language_overlay')
? '<a href="#" class="btn btn-default btn-sm" onclick="' . htmlspecialchars(BackendUtility::editOnClick($params))
. '" title="' . $this->getLanguageService()->getLL('edit', true) . '">'
? '<a href="' . htmlspecialchars($url) . '" class="btn btn-default btn-sm"'
. ' title="' . $this->getLanguageService()->getLL('edit', true) . '">'
. $this->iconFactory->getIcon('actions-open', Icon::SIZE_SMALL)->render() . '</a>'
: ''
);
......@@ -768,17 +827,24 @@ class PageLayoutView extends \TYPO3\CMS\Recordlist\RecordList\AbstractDatabaseRe
$editLink = '';
$recordIcon = '';
if ($this->getBackendUser()->checkLanguageAccess(0)) {
$params = '&edit[pages][' . $this->id . ']=edit';
$recordIcon = BackendUtility::wrapClickMenuOnIcon(
$this->iconFactory->getIconForRecord('pages', $this->pageRecord,
Icon::SIZE_SMALL)->render(),
'pages',
$this->id
);
$urlParameters = [
'edit' => [
'pages' => [
$this->id => 'edit'
]
],
'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
];
$url = BackendUtility::getModuleUrl('record_edit', $urlParameters);
$editLink = ($this->getBackendUser()->check('tables_modify', 'pages_language_overlay')
? '<a href="#" class="btn btn-default btn-sm" onclick="' . htmlspecialchars(BackendUtility::editOnClick($params))
. '" title="' . $this->getLanguageService()->getLL('edit', true) . '">'
? '<a href="' . htmlspecialchars($url) . '" class="btn btn-default btn-sm"'
. ' title="' . $this->getLanguageService()->getLL('edit', true) . '">'
. $this->iconFactory->getIcon('actions-open', Icon::SIZE_SMALL)->render() . '</a>'
: ''
);
......@@ -884,8 +950,16 @@ class PageLayoutView extends \TYPO3\CMS\Recordlist\RecordList\AbstractDatabaseRe
. '</tr>';
// Column's titles
if ($this->doEdit) {
$onClick = BackendUtility::editOnClick('&edit[' . $table . '][' . $this->id . ']=new');
$theData['__cmds__'] = '<a href="#" onclick="' . htmlspecialchars($onClick) . '" '
$urlParameters = [
'edit' => [
$table => [
$this->id => 'new'
]
],
'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
];
$url = BackendUtility::getModuleUrl('record_edit', $urlParameters);
$theData['__cmds__'] = '<a href="' . htmlspecialchars($url) . '" '
. 'title="' . $this->getLanguageService()->getLL('new', true) . '">'
. $this->iconFactory->getIcon('actions-document-new', Icon::SIZE_SMALL)->render() . '</a>';
}
......@@ -898,7 +972,6 @@ class PageLayoutView extends \TYPO3\CMS\Recordlist\RecordList\AbstractDatabaseRe
list($flag, $code) = $this->fwd_rwd_nav();
$out .= $code;
if ($flag) {
$params = '&edit[' . $table . '][' . $row['uid'] . ']=edit';
$Nrow = array();
// Setting icons links
if ($icon) {
......@@ -908,7 +981,16 @@ class PageLayoutView extends \TYPO3\CMS\Recordlist\RecordList\AbstractDatabaseRe
$Nrow = $this->dataFields($this->fieldArray, $table, $row, $Nrow);
// Attach edit icon
if ($this->doEdit && $this->getBackendUser()->doesUserHaveAccess($this->pageinfo, Permission::CONTENT_EDIT)) {
$Nrow['__editIconLink__'] = '<a href="#" onclick="' . htmlspecialchars(BackendUtility::editOnClick($params))
$urlParameters = [
'edit' => [
$table => [
$this->id => 'edit'
]
],
'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
];
$url = BackendUtility::getModuleUrl('record_edit', $urlParameters);
$Nrow['__editIconLink__'] = '<a href="' . htmlspecialchars($url)
. '" title="' . $this->getLanguageService()->getLL('edit', true) . '">'
. $this->iconFactory->getIcon('actions-document-open', Icon::SIZE_SMALL)->render() . '</a>';
} else {
......@@ -1116,9 +1198,16 @@ class PageLayoutView extends \TYPO3\CMS\Recordlist\RecordList\AbstractDatabaseRe
break;
case 'uid':
if ($this->getBackendUser()->doesUserHaveAccess($row, 2)) {
$params = '&edit[pages][' . $row['uid'] . ']=edit';
$eI = '<a href="#" onclick="'
. htmlspecialchars(BackendUtility::editOnClick($params))
$urlParameters = [
'edit' => [
'pages' => [
$row['uid'] => 'edit'
]
],
'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
];
$url = BackendUtility::getModuleUrl('record_edit', $urlParameters);
$eI = '<a href="' . htmlspecialchars($url)
. '" title="' . $this->getLanguageService()->getLL('editThisPage', true) . '">'
. $this->iconFactory->getIcon('actions-document-open', Icon::SIZE_SMALL)->render() . '</a>';
} else {
......@@ -1273,12 +1362,18 @@ class PageLayoutView extends \TYPO3\CMS\Recordlist\RecordList\AbstractDatabaseRe
// Render control panel for the element:
if ($this->tt_contentConfig['showCommands'] && $this->doEdit) {
// Edit content element:
$params = '&edit[tt_content][' . $this->tt_contentData['nextThree'][$row['uid']] . ']=edit';
$out .= '<a class="btn btn-default" href="#" onclick="' . htmlspecialchars(BackendUtility::editOnClick(
$params,
'',
GeneralUtility::getIndpEnv('REQUEST_URI') . '#element-tt_content-' . $row['uid']
)) . '" title="' . htmlspecialchars($this->nextThree > 1
$urlParameters = [
'edit' => [
'tt_content' => [
$this->tt_contentData['nextThree'][$row['uid']] => 'edit'
]
],
'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
];
$url = BackendUtility::getModuleUrl('record_edit', $urlParameters) . '#element-tt_content-' . $row['uid'];
$out .= '<a class="btn btn-default" href="' . htmlspecialchars($url)
. '" title="' . htmlspecialchars($this->nextThree > 1
? sprintf($this->getLanguageService()->getLL('nextThree'), $this->nextThree)
: $this->getLanguageService()->getLL('edit'))
. '">' . $this->iconFactory->getIcon('actions-document-open', Icon::SIZE_SMALL)->render() . '</a>';
......@@ -1736,15 +1831,21 @@ class PageLayoutView extends \TYPO3\CMS\Recordlist\RecordList\AbstractDatabaseRe
*/
public function linkEditContent($str, $row)
{
$addButton = '';
$onClick = '';
if ($this->doEdit && $this->getBackendUser()->recordEditAccessInternals('tt_content', $row)) {
// Setting onclick action for content link:
$onClick = BackendUtility::editOnClick('&edit[tt_content][' . $row['uid'] . ']=edit');
$urlParameters = [
'edit' => [
'tt_content' => [
$row['uid'] => 'edit'
]
],
'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
];
$url = BackendUtility::getModuleUrl('record_edit', $urlParameters);
// Return link
return '<a href="' . htmlspecialchars($url) . '" title="' . $this->getLanguageService()->getLL('edit', true) . '">' . $str . '</a>';
} else {
return $str;
}
// Return link
return $onClick ? '<a href="#" onclick="' . htmlspecialchars($onClick)
. '" title="' . $this->getLanguageService()->getLL('edit', true) . '">' . $str . '</a>' . $addButton : $str;
}
/**
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment