Skip to content

Commit

Permalink
Merge pull request #4122 from chihiro-adachi/preview-image
Browse files Browse the repository at this point in the history
ファイル管理:画像の場合はサムネイル表示を行うように対応
  • Loading branch information
kiy0taka committed Mar 29, 2019
2 parents e4f725e + 2901d77 commit acc4026
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
12 changes: 11 additions & 1 deletion src/Eccube/Resource/template/admin/Content/file.twig
Expand Up @@ -172,7 +172,17 @@ file that was distributed with this source code.
{% if file.is_dir %}
<i class="fa fa-folder-o fa-2x"></i>
{% else %}
<div class="d-inline-block p-3 bg-light">{{ file.extension|file_ext_icon({class: "fa-2x"}) }} </div>
{% if file.extension|file_ext_icon({}, true) == 'fa-file-image-o' %}
<div class="d-inline-block p-3 bg-light"
style="background: no-repeat center center;
background-image: url('{{ asset('', 'user_data') }}{{ file.file_path|slice(1) }}');
background-size: contain; width: 49px; height: 57px;">
</div>
{% else %}
<div class="d-inline-block p-3 bg-light">
{{ file.extension|file_ext_icon({class: "fa-2x"}) }}
</div>
{% endif %}
{% endif %}
</td>
<td class="align-middle">
Expand Down
10 changes: 9 additions & 1 deletion src/Eccube/Twig/Extension/EccubeExtension.php
Expand Up @@ -294,10 +294,11 @@ public function getClassCategoriesAsJson(Product $Product)
*
* @param $ext
* @param $attr
* @param $iconOnly アイコンのクラス名のみ返す場合はtrue
*
* @return string
*/
public function getExtensionIcon($ext, $attr = [])
public function getExtensionIcon($ext, $attr = [], $iconOnly = false)
{
$classes = [
'txt' => 'fa-file-text-o',
Expand Down Expand Up @@ -328,7 +329,14 @@ public function getExtensionIcon($ext, $attr = [])
'mov' => 'fa-file-video-o',
'mkv' => 'fa-file-video-o',
];
$ext = strtolower($ext);

$class = isset($classes[$ext]) ? $classes[$ext] : 'fa-file-o';

if ($iconOnly) {
return $class;
}

$attr['class'] = isset($attr['class'])
? $attr['class']." fa {$class}"
: "fa {$class}";
Expand Down
20 changes: 20 additions & 0 deletions tests/Eccube/Tests/Twig/Extension/EccubeExtensionTest.php
Expand Up @@ -76,4 +76,24 @@ function ($ProductClass) use ($actual) {
}
}
}

/**
* @dataProvider extensionProvider
*/
public function testGetExtensionIcon($ext, $iconOnly, $expected)
{
$actual = $this->Extension->getExtensionIcon($ext, [], $iconOnly);
$this->assertEquals($expected, $actual);
}

public function extensionProvider()
{
return [
['jpg', false, '<i class="fa fa-file-image-o" ></i>'],
['JPG', false, '<i class="fa fa-file-image-o" ></i>'],
['jpg', true, 'fa-file-image-o'],
['JPG', true, 'fa-file-image-o'],
];
}
}

0 comments on commit acc4026

Please sign in to comment.