Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions Classes/Controller/ModuleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@
namespace In2code\Alternative\Controller;

use In2code\Alternative\Domain\Service\AlternativeService;
use In2code\Alternative\Utility\FileUtility;
use Psr\Http\Message\ResponseInterface;
use TYPO3\CMS\Backend\Routing\UriBuilder;
use TYPO3\CMS\Core\Messaging\FlashMessage;
use TYPO3\CMS\Core\Messaging\FlashMessageService;
use TYPO3\CMS\Core\Resource\File;
use TYPO3\CMS\Core\Resource\FileRepository;
use TYPO3\CMS\Core\Resource\Folder;
use TYPO3\CMS\Core\Resource\ResourceFactory;
use TYPO3\CMS\Core\Type\ContextualFeedbackSeverity;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
Expand All @@ -23,6 +26,7 @@ public function __construct(
readonly protected FileRepository $fileRepository,
readonly protected FlashMessageService $flashMessageService,
readonly protected UriBuilder $uriBuilderCore,
readonly protected ResourceFactory $resourceFactory,
) {
}

Expand All @@ -44,6 +48,13 @@ public function addMetadataAction(int $file): ResponseInterface
}
return $this->openFileList($file);
}
public function addMetadataFromFolderAction(string $folderName): ResponseInterface
{
$folder = $this->resourceFactory->getFolderObjectFromCombinedIdentifier($folderName);
$this->addMetaDataToFolder($folder);

return $this->redirectToUri($this->uriBuilderCore->buildUriFromRoute('media_management', ['id' => $folder->getParentFolder()->getCombinedIdentifier()]));
}

protected function openFileList(File $file): ResponseInterface
{
Expand All @@ -58,4 +69,23 @@ protected function addMessage(string $message, ContextualFeedbackSeverity $sever
$messageQueue = $this->flashMessageService->getMessageQueueByIdentifier();
$messageQueue->addMessage($message);
}

protected function addMetaDataToFolder(Folder $folder): void
{
$successes = 0;
foreach ($folder->getFiles() as $file) {
if (FileUtility::isImage($file)) {
if ($this->alternativeService->setImageMetadata($file, false)) {
$successes++;
}
}
}

if ($successes) {
$key = $successes === 1 ? 'bulk_action_singular.finished' : 'bulk_action.finished';
$this->addMessage(LocalizationUtility::translate(
'LLL:EXT:alternative/Resources/Private/Language/Backend/locallang.xlf:' . $key, 'alternative', [$successes]
));
}
}
}
40 changes: 32 additions & 8 deletions Classes/EventListeners/AddFileButtonListener.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

declare(strict_types=1);
declare(strict_types = 1);

namespace In2code\Alternative\EventListeners;

Expand All @@ -14,7 +14,9 @@
use TYPO3\CMS\Core\Imaging\IconSize;
use TYPO3\CMS\Core\Information\Typo3Version;
use TYPO3\CMS\Core\Resource\File;
use TYPO3\CMS\Core\Resource\Folder;
use TYPO3\CMS\Core\Resource\ResourceInterface;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
use TYPO3\CMS\Filelist\Event\ProcessFileListActionsEvent;

Expand Down Expand Up @@ -63,6 +65,22 @@ protected function getButton(ProcessFileListActionsEvent $event, LinkButton $but
);
}

protected function createFolderButton(ProcessFileListActionsEvent $event): LinkButton
{
$buttonNew = GeneralUtility::makeInstance(LinkButton::class);
return $buttonNew
->setTitle(LocalizationUtility::translate(
'LLL:EXT:alternative/Resources/Private/Language/Backend/locallang.xlf:button.translate')
)
->setIcon($this->iconFactory->getIcon('extension-alternative-icon-magic', IconSize::SMALL))
->setHref(
(string)$this->uriBuilder->buildUriFromRoute(
'alternative_Module.Module_addMetadataFromFolder',
['folderName' => $event->getResource()->getStorage()->getUid() . ':' . $event->getResource()->getIdentifier()]
)
);
}

/**
* Todo: Can be removed once TYPO3 13 support is dropped
*
Expand All @@ -73,10 +91,14 @@ protected function addButtonLegacy(ProcessFileListActionsEvent $event): void
{
if ((new Typo3Version())->getMajorVersion() === 13) {
$actionItems = $event->getActionItems();
$actionItems = $this->insertArrayIntoArray(
$actionItems,
['metadata2' => $this->getButton($event, $actionItems['metadata'])]
);
if ($actionItems['metadata'] !== null) {
$actionItems = $this->insertArrayIntoArray(
$actionItems,
['metadata2' => $this->getButton($event, $actionItems['metadata'])]
);
} else {
$actionItems['metadata'] = $this->createFolderButton($event);
}
$event->setActionItems($actionItems);
}
}
Expand All @@ -100,10 +122,12 @@ protected function insertArrayIntoArray(array $existingArray, array $addArray, s
return array_merge($firstPart, $addArray, $lastPart);
}

protected function isActivated(ResourceInterface $file): bool
protected function isActivated(ResourceInterface $resource): bool
{
return is_a($file, File::class, true)
&& FileUtility::isImage($file)
return (
(is_a($resource, File::class, true) && FileUtility::isImage($resource))
|| is_a($resource, Folder::class, true)
)
&& $this->hasAccessToModule()
&& ConfigurationUtility::getConfigurationByKey('showButtonInFileList') === '1';
}
Expand Down
1 change: 1 addition & 0 deletions Configuration/Backend/Modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
'controllerActions' => [
ModuleController::class => [
'addMetadata',
'addMetadataFromFolder',
],
],
],
Expand Down
11 changes: 10 additions & 1 deletion Resources/Private/Language/Backend/de.locallang.xlf
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<xliff version="1.0">
<file source-language="en" target-language="de" datatype="plaintext" original="messages" date="2026-01-01T12:00:00Z" product-name="alternative">
<file source-language="en" target-language="de" datatype="plaintext" original="messages" date="2026-01-01T12:00:00Z"
product-name="alternative">
<header/>
<body>
<trans-unit id="button.translate">
Expand All @@ -15,6 +16,14 @@
<source>Metadata could not be added</source>
<target state="translated">Metadaten konnten nicht gesetzt werden</target>
</trans-unit>
<trans-unit id="bulk_action_singular.finished">
<source>Metadata successfully added for %1$s file</source>
<target state="translated">Metadaten erfolgreich für %1$s Datei gesetzt</target>
</trans-unit>
<trans-unit id="bulk_action.finished">
<source>Metadata successfully added for %1$s files</source>
<target state="translated">Metadaten erfolgreich für %1$s Dateien gesetzt</target>
</trans-unit>
</body>
</file>
</xliff>
6 changes: 6 additions & 0 deletions Resources/Private/Language/Backend/locallang.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
<trans-unit id="action.notfinished">
<source>Metadata could not be added</source>
</trans-unit>
<trans-unit id="bulk_action_singular.finished">
<source>Metadata successfully added for %1$s file</source>
</trans-unit>
<trans-unit id="bulk_action.finished">
<source>Metadata successfully added for %1$s files</source>
</trans-unit>
</body>
</file>
</xliff>