Skip to content

Commit

Permalink
[TASK] TYPO3 v11 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
fabarea committed May 3, 2022
1 parent d5e96dc commit 8c7194d
Show file tree
Hide file tree
Showing 3 changed files with 150 additions and 58 deletions.
8 changes: 0 additions & 8 deletions Classes/Controller/MediaUploadController.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ class MediaUploadController extends ActionController

/**
* Initialize actions. These actions are meant to be called by an logged-in FE User.
* @throws \TYPO3\CMS\Core\Resource\Exception
* @throws \TYPO3\CMS\Extbase\SignalSlot\Exception\InvalidSlotException
* @throws \TYPO3\CMS\Extbase\SignalSlot\Exception\InvalidSlotReturnException
*/
public function initializeAction()
{
Expand Down Expand Up @@ -63,9 +60,6 @@ public function initializeAction()
* Delete a file being just uploaded.
*
* @return string
* @throws \TYPO3\CMS\Extbase\Mvc\Exception\UnsupportedRequestTypeException
* @throws \TYPO3\CMS\Extbase\Mvc\Exception\StopActionException
* @throws \InvalidArgumentException
*/
public function deleteAction()
{
Expand Down Expand Up @@ -143,8 +137,6 @@ protected function getFrontendUser()
* Signal that is emitted before upload processing is called.
*
* @return void
* @throws \TYPO3\CMS\Extbase\SignalSlot\Exception\InvalidSlotReturnException
* @throws \TYPO3\CMS\Extbase\SignalSlot\Exception\InvalidSlotException
*/
protected function emitBeforeHandleUploadSignal()
{
Expand Down
70 changes: 46 additions & 24 deletions Classes/ViewHelpers/Widget/ShowUploadedViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,41 +8,63 @@
* LICENSE.md file that was distributed with this source code.
*/

use TYPO3\CMS\Fluid\Core\Widget\AbstractWidgetViewHelper;
use Fab\MediaUpload\Service\UploadFileService;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Fluid\View\StandaloneView;
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;

/**
* Widget which displays a media upload.
*/
class ShowUploadedViewHelper extends AbstractWidgetViewHelper
class ShowUploadedViewHelper extends AbstractViewHelper
{

/**
* @var \Fab\MediaUpload\ViewHelpers\Widget\Controller\ShowUploadedController
*/
protected $controller;

/**
* @param \Fab\MediaUpload\ViewHelpers\Widget\Controller\ShowUploadedController $controller
*/
public function injectController(\Fab\MediaUpload\ViewHelpers\Widget\Controller\ShowUploadedController $controller ) {
$this->controller = $controller ;
}

/**
* @return void
*/
public function initializeArguments()
{
$this->registerArgument('property', 'int', 'The property name used for identifying and grouping uploaded files. Required if form contains multiple upload fields', FALSE, '');
$this->registerArgument(
'property',
'int',
'The property name used for identifying and grouping uploaded files. Required if form contains multiple upload fields',
false,
'',
);
}

/**
* Returns an carousel widget
*
* @return string
*/
public function render()
public function render(): string
{
return $this->initiateSubRequest();
$uploadFileService = GeneralUtility::makeInstance(
UploadFileService::class,
);

return static::renderStatic(
[
'property' => $this->arguments['property'],
'uploadedFileList' => $uploadFileService->getUploadedFileList(
$this->arguments['property'],
),
'uploadedFiles' => $uploadFileService->getUploadedFiles(
$this->arguments['property'],
),
],
$this->buildRenderChildrenClosure(),
$this->renderingContext,
);
}

public static function renderStatic(
array $arguments,
\Closure $renderChildrenClosure,
RenderingContextInterface $renderingContext
): string {
/** @var StandaloneView $view */
$view = GeneralUtility::makeInstance(StandaloneView::class);

$view->setTemplatePathAndFilename(
'EXT:media_upload/Resources/Private/Templates/ViewHelpers/Widget/ShowUploaded/Index.html',
);
$view->assignMultiple($arguments);
return $view->render();
}
}
130 changes: 104 additions & 26 deletions Classes/ViewHelpers/Widget/UploadViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,47 +8,125 @@
* LICENSE.md file that was distributed with this source code.
*/

use TYPO3\CMS\Fluid\Core\Widget\AbstractWidgetViewHelper;
use Fab\Media\Utility\PermissionUtility;
use Fab\MediaUpload\Service\UploadFileService;
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Fluid\View\StandaloneView;
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;

/**
* Widget which displays a media upload.
*/
class UploadViewHelper extends AbstractWidgetViewHelper
class UploadViewHelper extends AbstractViewHelper
{
public function initializeArguments()
{
$this->registerArgument(
'allowedExtensions',
'string',
'Allowed extension to be uploaded.',
false,
'',
)
->registerArgument(
'maximumSize',
'int',
'Maximum file size in Mo by default.',
false,
0,
)
->registerArgument(
'sizeUnit',
'string',
'Whether it is Ko or Mo.',
false,
'Mo',
)
->registerArgument(
'storage',
'int',
'The final storage identifier to which the file will be added eventually.',
true,
)
->registerArgument(
'maximumItems',
'int',
'Maximum items to be uploaded',
false,
10,
)
->registerArgument(
'property',
'int',
'The property name used for identifying and grouping uploaded files. Required if form contains multiple upload fields',
false,
'',
);
}

/**
* @var \Fab\MediaUpload\ViewHelpers\Widget\Controller\UploadController
*/
protected $controller;
public function render(): string
{
$uploadFileService = GeneralUtility::makeInstance(
UploadFileService::class,
);

/**
* @param \Fab\MediaUpload\ViewHelpers\Widget\Controller\UploadController $controller
*/
public function injectController(\Fab\MediaUpload\ViewHelpers\Widget\Controller\UploadController $controller ) {
$this->controller = $controller ;
return static::renderStatic(
[
'allowedExtensions' => $this->arguments['allowedExtensions'],
'maximumSize' => $this->arguments['maximumSize'],
'maximumSizeLabel' => self::getMaximumSizeLabel(
(int) $this->arguments['maximumSize'],
),
'sizeUnit' => $this->arguments['sizeUnit'],
'storage' => $this->arguments['storage'],
'maximumItems' => $this->arguments['maximumItems'],
'property' => $this->arguments['property'],
'uploadedFileList' => $uploadFileService->getUploadedFileList(
$this->arguments['property'],
),
'widgetIdentifier' => uniqid(),
],
$this->buildRenderChildrenClosure(),
$this->renderingContext,
);
}

/**
* @return void
* @throws \TYPO3\CMS\Fluid\Core\ViewHelper\Exception
*/
public function initializeArguments()
public static function renderStatic(
array $arguments,
\Closure $renderChildrenClosure,
RenderingContextInterface $renderingContext
): string {
/** @var StandaloneView $view */
$view = GeneralUtility::makeInstance(StandaloneView::class);

$view->setTemplatePathAndFilename(
'EXT:media_upload/Resources/Private/Templates/ViewHelpers/Widget/Upload/Index.html',
);
$view->assignMultiple($arguments);
return $view->render();
}

public static function getMaximumSizeLabel(int $maximumSize = 0): int
{
$this->registerArgument('allowedExtensions', 'string', 'Allowed extension to be uploaded.', FALSE, '');
$this->registerArgument('maximumSize', 'int', 'Maximum file size in Mo by default.', FALSE, 0);
$this->registerArgument('sizeUnit', 'string', 'Whether it is Ko or Mo.', FALSE, 'Mo');
$this->registerArgument('storage', 'int', 'The final storage identifier to which the file will be added eventually.', TRUE);
$this->registerArgument('maximumItems', 'int', 'Maximum items to be uploaded', FALSE, 10);
$this->registerArgument('property', 'int', 'The property name used for identifying and grouping uploaded files. Required if form contains multiple upload fields', FALSE, '');
$maximumSizeLabel = GeneralUtility::getMaxUploadFileSize() / 1024;
if ($maximumSize > 0) {
$maximumSizeLabel = $maximumSize;
}

return (int) $maximumSizeLabel;
}

/**
* Returns an carousel widget
*
* @param string $property
* @return string
*/
public function render()
public static function getUploadedFileList($property = ''): string
{
return $this->initiateSubRequest();
$parameters = GeneralUtility::_GPmerged('tx_mediaupload_pi1');
return empty($parameters['uploadedFiles'][$property])
? ''
: $parameters['uploadedFiles'][$property];
}
}

0 comments on commit 8c7194d

Please sign in to comment.