Add file check for image upload form widgets - Fixes #3653

This commit is contained in:
Samuel Georges 2019-03-29 02:23:20 +11:00
parent 2b1323b7b2
commit 6593651331
3 changed files with 13 additions and 5 deletions

View File

@ -84,8 +84,11 @@ class MediaFinder extends FormWidgetBase
public function prepareVars()
{
$value = $this->getLoadValue();
$isImage = $this->mode === 'image';
$this->vars['value'] = $value;
$this->vars['imageUrl'] = $value ? MediaLibrary::url($value) : '';
$this->vars['imageUrl'] = $isImage && $value ? MediaLibrary::url($value) : '';
$this->vars['imageExists'] = $isImage && $value ? MediaLibrary::instance()->exists($value) : '';
$this->vars['field'] = $this->formField;
$this->vars['prompt'] = str_replace('%s', '<i class="icon-folder"></i>', trans($this->prompt));
$this->vars['mode'] = $this->mode;

View File

@ -13,9 +13,13 @@
<!-- Existing value -->
<div class="find-object">
<div class="icon-container">
<img data-find-image src="<?= $imageUrl ?>" alt="" />
</div>
<?php if ($imageExists): ?>
<div class="icon-container">
<img data-find-image src="<?= $imageUrl ?>" alt="" />
</div>
<?php else: ?>
<p class="help-block"><?= e(trans('backend::lang.mediafinder.no_image')) ?></p>
<?php endif ?>
<div class="info">
<h4 class="filename">
<span data-find-file-name><?= ltrim($value, '/') ?></span>

View File

@ -553,7 +553,8 @@ return [
],
'mediafinder' => [
'label' => 'Media Finder',
'default_prompt' => 'Click the %s button to find a media item'
'default_prompt' => 'Click the %s button to find a media item',
'no_image' => 'The image could not be found'
],
'media' => [
'menu_label' => 'Media',