Skip to content

Commit

Permalink
pkp/pkp-lib#6927 Fix coverImage not shown and coverImage unable to de…
Browse files Browse the repository at this point in the history
…lete (#62)
  • Loading branch information
defstat authored Oct 24, 2022
1 parent 57f1047 commit e7f99bd
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
8 changes: 5 additions & 3 deletions classes/form/UploadImageForm.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ function initData() {

$this->setData('coverImage', $coverImage);
$this->setData('imageAltText', $coverImage['altText'] ?? '');
$this->setData('coverImageName', $coverImage['uploadName'] ?? '');
}

/**
Expand All @@ -130,7 +131,7 @@ function deleteCoverImage($request) {
// Remove cover image and alt text from article settings
$locale = Locale::getLocale();
$this->publication->setData('coverImage', []);
Repo::publication()->edit($this->publication);
Repo::publication()->edit($this->publication, []);

// Remove the file
$publicFileManager = new PublicFileManager();
Expand Down Expand Up @@ -166,13 +167,14 @@ function execute(...$functionArgs) {

$newFileName = 'article_' . $this->submissionId . '_cover_' . $locale . $fileManager->getImageExtension($temporaryFile->getFileType());

$publicFileManager = new PublicFileManager();
if ($publicFileManager->copyContextFile($this->context->getId(), $temporaryFile->getFilePath(), $newFileName)) {

$this->publication->setData('coverImage', [
'altText' => $this->getData('imageAltText'),
'uploadName' => $newFileName,
], $locale);
Repo::publication()->edit($this->publication);
Repo::publication()->edit($this->publication, []);

// Clean up the temporary file.
$this->removeTemporaryFile($this->request);
Expand All @@ -183,7 +185,7 @@ function execute(...$functionArgs) {
$coverImage = $this->publication->getData('coverImage');
$coverImage[$locale]['altText'] = $this->getData('imageAltText');
$this->publication->setData('coverImage', $coverImage);
Repo::publication()->edit($this->publication);
Repo::publication()->edit($this->publication, []);
return DAO::getDataChangedEvent();
}
return new JSONMessage(false, __('common.uploadFailed'));
Expand Down
2 changes: 1 addition & 1 deletion templates/uploadImageForm.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
{if $coverImage != ''}
<div class="pkp_form_file_view pkp_form_image_view">
<div class="img">
<img src="{$publicFilesDir}/{$coverImage|escape:"url"}{'?'|uniqid}" {if $coverImageAlt !== ''} alt="{$coverImageAlt|escape}"{/if}>
<img src="{$publicFilesDir}/{$coverImageName|escape:"url"}{'?'|uniqid}" {if $imageAltText !== ''} alt="{$imageAltText|escape}"{/if}>
</div>

<div class="data">
Expand Down

0 comments on commit e7f99bd

Please sign in to comment.