Created
July 7, 2017 05:19
-
-
Save MattiasNilsson/ce35259e15d97c16e4a8de95929e996b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
declare(strict_types=1); | |
namespace Pixelant\PxaMedaT3kit\Hooks; | |
use TYPO3\CMS\Core\Utility\GeneralUtility; | |
use TYPO3\CMS\FrontendEditing\EditingPanel\FrontendEditingDropzoneModifier; | |
use Pixelant\PxaMedaT3kit\Xclass\FrontendEditing\Service\ContentEditableWrapperService; | |
/** | |
* Class DropzoneModifier | |
* @package Pixelant\PxaMedaT3kit\Hooks | |
*/ | |
class DropzoneModifier implements FrontendEditingDropzoneModifier | |
{ | |
/** | |
* Keep list of grid container that has first dropzone | |
* | |
* @var string | |
*/ | |
protected static $containersWithContent = ''; | |
/** | |
* @param string $table | |
* @param int $editUid | |
* @param array $dataArr | |
* @param string $content | |
* @return bool | |
*/ | |
public function wrapWithDropzone( | |
string $table, | |
int $editUid, | |
array $dataArr, | |
string &$content | |
): bool { | |
if ($dataArr['tx_gridelements_container']) { | |
/** @var ContentEditableWrapperService $wrapperService */ | |
$wrapperService = GeneralUtility::makeInstance(ContentEditableWrapperService::class); | |
$params = [ | |
'tx_gridelements_container' => $dataArr['tx_gridelements_container'], | |
'tx_gridelements_columns' => $dataArr['tx_gridelements_columns'] | |
]; | |
$content = $wrapperService->wrapContentWithDropzone( | |
$table, | |
(int)$editUid, | |
$content, | |
-1 | |
); | |
$containerIdentifier = $dataArr['tx_gridelements_container'] . $dataArr['tx_gridelements_columns']; | |
if (!GeneralUtility::inList(self::$containersWithContent, $containerIdentifier)) { | |
$content = $wrapperService->wrapContentWithDropzone( | |
$table, | |
0, | |
$content, | |
-1, | |
$params, | |
true | |
); | |
self::$containersWithContent .= ',' . $containerIdentifier; | |
} | |
$content = str_replace( | |
[ | |
'ondragstart="window.parent.F.dragCeStart(event)"', | |
'###GRID_DATA###' | |
], | |
[ | |
'ondragstart="window.parent.F.dragCeInsideGridStart(event)"', | |
sprintf('data-params="%s"', GeneralUtility::implodeArrayForUrl('', $params)) | |
], | |
$content | |
); | |
return true; | |
} | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment