Skip to content

Commit

Permalink
[TASK] Streamline FAL pre-emit signals for createFile and setContent
Browse files Browse the repository at this point in the history
In order to streamline the FAL API the following signals have been added.
The according post-processing signals have been available already before:

+ ResourceStorageInterface::SIGNAL_PreFileCreate
+ ResourceStorageInterface::SIGNAL_PreFileSetContents

Resolves: #85434
Releases: master, 8.7
Change-Id: I41fc07afbc4e1a393c8a26fe02f431a7b62015d8
Reviewed-on: https://review.typo3.org/57564
Reviewed-by: Benni Mack <benni@typo3.org>
Tested-by: Benni Mack <benni@typo3.org>
  • Loading branch information
ohader authored and bmack committed Jul 12, 2018
1 parent 098478a commit 75f577e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
24 changes: 24 additions & 0 deletions typo3/sysext/core/Classes/Resource/ResourceStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -1678,6 +1678,7 @@ public function setFileContents(AbstractFile $file, $contents)
{
// Check if user is allowed to edit
$this->assureFileWritePermissions($file);
$this->emitPreFileSetContentsSignal($file, $contents);
// Call driver method to update the file and update file index entry afterwards
$result = $this->driver->setFileContents($file->getIdentifier(), $contents);
if ($file instanceof File) {
Expand All @@ -1702,6 +1703,7 @@ public function setFileContents(AbstractFile $file, $contents)
public function createFile($fileName, Folder $targetFolderObject)
{
$this->assureFileAddPermissions($targetFolderObject, $fileName);
$this->emitPreFileCreateSignal($fileName, $targetFolderObject);
$newFileIdentifier = $this->driver->createFile($fileName, $targetFolderObject->getIdentifier());
$this->emitPostFileCreateSignal($newFileIdentifier, $targetFolderObject);
return $this->getResourceFactoryInstance()->getFileObjectByStorageAndIdentifier($this->getUid(), $newFileIdentifier);
Expand Down Expand Up @@ -2564,6 +2566,17 @@ protected function emitPostFileReplaceSignal(FileInterface $file, $localFilePath
$this->getSignalSlotDispatcher()->dispatch(self::class, self::SIGNAL_PostFileReplace, [$file, $localFilePath]);
}

/**
* Emits the file pre-create signal
*
* @param string $fileName
* @param Folder $targetFolder
*/
protected function emitPreFileCreateSignal(string $fileName, Folder $targetFolder)
{
$this->getSignalSlotDispatcher()->dispatch(self::class, self::SIGNAL_PreFileCreate, [$fileName, $targetFolder]);
}

/**
* Emits the file post-create signal
*
Expand Down Expand Up @@ -2595,6 +2608,17 @@ protected function emitPostFileDeleteSignal(FileInterface $file)
$this->getSignalSlotDispatcher()->dispatch(self::class, self::SIGNAL_PostFileDelete, [$file]);
}

/**
* Emits the file pre-set-contents signal
*
* @param FileInterface $file
* @param mixed $content
*/
protected function emitPreFileSetContentsSignal(FileInterface $file, $content)
{
$this->getSignalSlotDispatcher()->dispatch(self::class, self::SIGNAL_PreFileSetContents, [$file, $content]);
}

/**
* Emits the file post-set-contents signal
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ interface ResourceStorageInterface
const SIGNAL_SanitizeFileName = 'sanitizeFileName';
const SIGNAL_PreFileAdd = 'preFileAdd';
const SIGNAL_PostFileAdd = 'postFileAdd';
const SIGNAL_PreFileCreate = 'preFileCreate';
const SIGNAL_PostFileCreate = 'postFileCreate';
const SIGNAL_PreFileCopy = 'preFileCopy';
const SIGNAL_PostFileCopy = 'postFileCopy';
Expand All @@ -33,6 +34,7 @@ interface ResourceStorageInterface
const SIGNAL_PostFileRename = 'postFileRename';
const SIGNAL_PreFileReplace = 'preFileReplace';
const SIGNAL_PostFileReplace = 'postFileReplace';
const SIGNAL_PreFileSetContents = 'preFileSetContents';
const SIGNAL_PostFileSetContents = 'postFileSetContents';
const SIGNAL_PreFolderAdd = 'preFolderAdd';
const SIGNAL_PostFolderAdd = 'postFolderAdd';
Expand Down

0 comments on commit 75f577e

Please sign in to comment.