Skip to content

Commit

Permalink
[BUFIX] Use core /record/process ajax route when moving CEs (#688)
Browse files Browse the repository at this point in the history
Resolves: #687
  • Loading branch information
webian authored Aug 4, 2023
1 parent 55c5ffa commit fce3bdf
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 28 deletions.
2 changes: 2 additions & 0 deletions Classes/EditingPanel/FrontendEditingPanel.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ public function editIcons(
$content = $wrapperService->wrapContentWithDropzone(
$table,
(int)$editUid,
$dataArr['pid'],
$content,
(int)$dataArr['colPos']
);
Expand All @@ -196,6 +197,7 @@ public function editIcons(
$content = $wrapperService->wrapContentWithDropzone(
$table,
0,
$dataArr['pid'],
$content,
(int)$dataArr['colPos'],
[],
Expand Down
5 changes: 4 additions & 1 deletion Classes/Hook/FrontendEditingInitializationHook.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,9 @@ public function main(array $params, TypoScriptFrontendController $parentObject)
$uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
$endpointUrl = $uriBuilder->buildUriFromRoute(
'ajax_frontendediting_process',
['page' => $this->typoScriptFrontendController->id]
);
$ajaxRecordProcessEndpointUrl = $uriBuilder->buildUriFromRoute(
'ajax_record_process',
);
$configurationEndpointUrl = $uriBuilder->buildUriFromRoute(
'ajax_frontendediting_editorconfiguration',
Expand Down Expand Up @@ -268,6 +270,7 @@ public function main(array $params, TypoScriptFrontendController $parentObject)
editorConfigurationUrl: ' . GeneralUtility::quoteJSvalue($configurationEndpointUrl) . '
});
window.F.setEndpointUrl(' . GeneralUtility::quoteJSvalue($endpointUrl) . ');
window.F.setAjaxRecordProcessEndpointUrl(' . GeneralUtility::quoteJSvalue($ajaxRecordProcessEndpointUrl) . ');
window.F.setBESessionId(' . GeneralUtility::quoteJSvalue($this->getBeSessionKey()) . ');
window.F.setTranslationLabels(' . json_encode($this->getLocalizedFrontendLabels()) . ');
window.F.setDisableModalOnNewCe(' .
Expand Down
16 changes: 10 additions & 6 deletions Classes/Service/ContentEditableWrapperService.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,15 +209,15 @@ public function wrapContent(string $table, int $uid, array $dataArr, string $con
$inlineActionTagBuilder = GeneralUtility::makeInstance(
TagBuilder::class,
'span',
$this->renderInlineActionIcons($table, $elementIsHidden, $recordTitle)
$this->renderInlineActionIcons($table, $elementIsHidden, $recordTitle, $dataArr['sys_language_uid'] ?? 0)
);
$inlineActionTagBuilder->forceClosingTag(true);

$inlineActionTagBuilder->addAttributes([
'style' => 'display:none;',
'class' => $class,
'data-table' => $table,
'data-uid' => (int)$uid,
'data-uid' => $uid,
'data-hidden' => (int)$elementIsHidden,
'data-cid' => $dataArr['colPos'] ?? 0,
'data-edit-url' => $this->renderEditOnClickReturnUrl($this->renderEditUrl($table, $uid)),
Expand All @@ -236,6 +236,7 @@ public function wrapContent(string $table, int $uid, array $dataArr, string $con
$tagBuilder->addAttributes([
'class' => 't3-frontend-editing__ce ' . $hiddenElementClassName,
'title' => $recordTitle,
'data-uid' => $uid,
]);

return $tagBuilder->render();
Expand All @@ -256,6 +257,7 @@ public function wrapContent(string $table, int $uid, array $dataArr, string $con
public function wrapContentWithDropzone(
string $table,
int $uid,
int $pid,
string $content,
int $colPos = 0,
array $defaultValues = [],
Expand Down Expand Up @@ -288,12 +290,13 @@ public function wrapContentWithDropzone(
'data-new-url' => $this->renderEditOnClickReturnUrl(
$this->renderNewUrl(
$table,
(int)$uid,
(int)$colPos,
$uid,
$colPos,
$defaultValues
)
),
'data-moveafter' => (int)$uid,
'data-moveafter' => $uid,
'data-pid' => $pid,
'data-colpos' => $colPos,
'data-defvals' => json_encode($defaultValues),
]);
Expand Down Expand Up @@ -365,13 +368,14 @@ public function wrapContentWithCustomDropzone(
* @param string $recordTitle
* @return string
*/
public function renderInlineActionIcons(string $table, bool $elementIsHidden, string $recordTitle = ''): string
public function renderInlineActionIcons(string $table, bool $elementIsHidden, string $recordTitle = '', int $langUid = 0): string
{
$this->iconFactory = GeneralUtility::makeInstance(IconFactory::class);

$dragAndDropHandleIcon = '<span '
. 'class="t3-frontend-editing__handle" '
. 'title="' . $GLOBALS['LANG']->sL('LLL:EXT:frontend_editing/Resources/Private/Language/locallang.xlf:move') . ' \'' . $recordTitle . '\'" '
. 'data-lang="' . $langUid . '"'
. 'data-movable="1" draggable="true" ondragstart="window.parent.F.dragCeStart(event)" ondragend="window.parent.F.dragCeEnd(event)"'
. '>' . $this->iconFactory->getIcon('actions-move', Icon::SIZE_SMALL)->render() . '</span>';

Expand Down
1 change: 1 addition & 0 deletions Documentation/NewContentElements/Index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ It's possible to add drop zones for new content elements in a custom content ele
$content = $wrapperService->wrapContentWithDropzone(
'tt_content', // table name
$uid, // CE uid
-1, // page uid, pid
$content,
0, // colPos
Expand Down
36 changes: 18 additions & 18 deletions Resources/Public/JavaScript/Crud.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ define([
FrontendEditing.prototype.setBESessionId = setBESessionId;
FrontendEditing.prototype.getEndpointUrl = getEndpointUrl;
FrontendEditing.prototype.setEndpointUrl = setEndpointUrl;
FrontendEditing.prototype.setAjaxRecordProcessEndpointUrl = setAjaxRecordProcessEndpointUrl;

var numberOfRequestsLeft;

Expand All @@ -71,6 +72,12 @@ define([
this._endpointUrl = url;
}

function setAjaxRecordProcessEndpointUrl (url) {
log.log('setAjaxRecordProcessEndpointUrl', url);

this._ajaxRecordProcessEndpointUrl = url;
}

function getBESessionId () {
return F._beSessionId;
}
Expand Down Expand Up @@ -292,36 +299,29 @@ define([
appendTriggers(jqxhr);
}

function moveRecord (uid, table, beforeUid, colPos, defVals) {
var moveEndpoint = getEndpointUrl('move');
function moveRecord (uid, beforeUid, colPos, languageUid) {
var moveEndpoint = F._ajaxRecordProcessEndpointUrl;

log.info(
'move record [moveEndpoint, uid, table, beforeUid, colPos, defVals]',
'move record [moveEndpoint, uid, beforeUid, colPos, languageUid]',
moveEndpoint,
uid,
table,
beforeUid,
colPos,
defVals
languageUid
);

this.trigger(F.REQUEST_START);

var data = {
uid: uid,
table: table,
beforeUid: beforeUid,
defVals: defVals
};

if (typeof colPos !== 'undefined') {
data.colPos = colPos;
}
moveEndpoint = moveEndpoint
+ '&cmd[tt_content][' + uid + '][move][action]=paste'
+ '&cmd[tt_content][' + uid + '][move][target]=' + beforeUid
+ '&cmd[tt_content][' + uid + '][move][update][colPos]=' + colPos
+ '&cmd[tt_content][' + uid + '][move][update][sys_language_uid]=' + languageUid
;

var jqxhr = $.ajax({
url: moveEndpoint,
method: 'POST',
data: data
url: moveEndpoint
});

appendTriggers(jqxhr);
Expand Down
15 changes: 12 additions & 3 deletions Resources/Public/JavaScript/FrontendEditing.js
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,7 @@ define([

ev.dataTransfer.setData('params', ev.currentTarget.dataset.params);
ev.dataTransfer.setData('movable', movable);
ev.dataTransfer.setData('lang', ev.currentTarget.dataset.lang);
ev.dataTransfer.setData('movableUid', $dragHandle
.parent('span.t3-frontend-editing__inline-actions')
.data('uid'));
Expand Down Expand Up @@ -509,17 +510,25 @@ define([
if (movable === 1) {
var $currentTarget = $(ev.currentTarget);
var ceUid = parseInt(ev.dataTransfer.getData('movableUid'), 10);

var moveAfter = parseInt($currentTarget.data('moveafter'), 10);
// If the CE is dropped after an exising CE (moveAfter > 0), then 'target' is -uid of the existing CE
// If the CE is dropped as first in a column, then 'target' is the page uid
moveAfter = (moveAfter > 0) ? -moveAfter : parseInt($currentTarget.data('pid'), 10);

var colPos = parseInt($currentTarget.data('colpos'), 10);
var defVals = $currentTarget.data('defvals');
// If the target drop area is descendant of another CE, then append the uid of this CE
var $parentCE = $currentTarget.closest('.t3-frontend-editing__ce');
if ($parentCE.length) {
colPos = parseInt($parentCE.data('uid'), 10) + '-' + colPos;
}

if (ceUid !== moveAfter) {
F.moveContent(
ceUid,
'tt_content',
moveAfter,
colPos,
defVals
ev.dataTransfer.getData('lang')
);
}
} else {
Expand Down

0 comments on commit fce3bdf

Please sign in to comment.