Commit bd04cd12 authored by Benni Mack's avatar Benni Mack Committed by Susanne Moog
Browse files

[TASK] Add new file object to AfterFileCopiedEvent

The PSR-14 event "AfterFileCopiedEvent" in FAL now also
has the possibility to return the newly created file
and the identifier.

Resolves: #91373
Releases: master
Change-Id: I08a01a0424e37fe2f010d2894d41a14628bdc950
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/64478


Tested-by: default avatarTYPO3com <noreply@typo3.com>
Tested-by: Daniel Goerz's avatarDaniel Goerz <daniel.goerz@posteo.de>
Tested-by: Susanne Moog's avatarSusanne Moog <look@susi.dev>
Reviewed-by: Daniel Goerz's avatarDaniel Goerz <daniel.goerz@posteo.de>
Reviewed-by: Susanne Moog's avatarSusanne Moog <look@susi.dev>
parent 287e14c3
......@@ -38,10 +38,22 @@ final class AfterFileCopiedEvent
*/
private $folder;
public function __construct(FileInterface $file, Folder $folder)
/**
* @var string
*/
private $newFileIdentifier;
/**
* @var FileInterface|null
*/
private $newFile;
public function __construct(FileInterface $file, Folder $folder, string $newFileIdentifier, ?FileInterface $newFile)
{
$this->file = $file;
$this->folder = $folder;
$this->newFileIdentifier = $newFileIdentifier;
$this->newFile = $newFile;
}
public function getFile(): FileInterface
......@@ -53,4 +65,14 @@ final class AfterFileCopiedEvent
{
return $this->folder;
}
public function getNewFileIdentifier(): string
{
return $this->newFileIdentifier;
}
public function getNewFile(): ?FileInterface
{
return $this->newFile;
}
}
......@@ -1949,7 +1949,7 @@ class ResourceStorage implements ResourceStorageInterface
$newFileObject = $this->getResourceFactoryInstance()->getFileObjectByStorageAndIdentifier($this->getUid(), $newFileObjectIdentifier);
$this->eventDispatcher->dispatch(
new AfterFileCopiedEvent($file, $targetFolder)
new AfterFileCopiedEvent($file, $targetFolder, $newFileObjectIdentifier, $newFileObject)
);
return $newFileObject;
}
......
......@@ -63,6 +63,9 @@ it is highly encouraged to migrate to the new PSR-14 based events.
In addition, all Core hooks using these events have been migrated to new PSR-14 events,
all new Events have a description when to use them and what the benefits are.
The Event `AfterFileCopiedEvent` in addition also contains the newly created File
object.
Have a look at the new PHP classes to understand the Events and to learn more about PSR-14.
.. index:: FAL, PHP-API, ext:core
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