Skip to content

Commit 43ee35f

Browse files
committed
カスタムコンテンツのファイル拡張子チェックのデフォルト値を設定
1 parent 2393fe4 commit 43ee35f

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

plugins/bc-admin-third/templates/plugin/BcCustomContent/Admin/element/CustomFields/form.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@
127127
</li>
128128
<li>
129129
<strong><?php echo __d('baser_core', 'ファイル拡張子チェック') ?></strong><br>
130-
<?php echo __d('baser_core', '利用するには、「アップロードを許可する拡張子」に拡張子をカンマ区切りで入力します') ?>
130+
<?php echo __d('baser_core', '利用するには、「アップロードを許可する拡張子」に拡張子をカンマ区切りで入力します。未設定の場合は「gif,jpg,jpeg,png,pdf」を許可します。') ?>
131131
</li>
132132
</ul>
133133
</div>

plugins/bc-custom-content/src/Model/Table/CustomEntriesTable.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -336,8 +336,15 @@ public function setValidateMaxFileSize(Validator $validator, CustomLink $link, a
336336
*/
337337
public function setValidateFileExt(Validator $validator, CustomLink $link)
338338
{
339-
if (empty($link->custom_field->meta['BcCustomContent']['file_ext'])) return $validator;
340-
$fileExt = explode(',', $link->custom_field->meta['BcCustomContent']['file_ext']);
339+
if ($link->custom_field->type !== 'BcCcFile') {
340+
return $validator;
341+
}
342+
343+
$fileExt = ['gif', 'jpg', 'jpeg', 'png', 'pdf'];
344+
if (!empty($link->custom_field->meta['BcCustomContent']['file_ext'])) {
345+
$fileExt = explode(',', $link->custom_field->meta['BcCustomContent']['file_ext']);
346+
}
347+
341348
$validator->add($link->name, [
342349
'fileExt' => [
343350
'provider' => 'bc',

plugins/bc-custom-content/tests/TestCase/Model/Table/CustomEntriesTableTest.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,7 @@ public function test_setupValidate()
372372
//準備
373373
CustomFieldFactory::make([
374374
'id' => 1,
375+
'type' => 'BcCcFile',
375376
'validate' => '["NUMBER","EMAIL","HANKAKU","ZENKAKU_KATAKANA","ZENKAKU_HIRAGANA","DATETIME","EMAIL_CONFIRM"]',
376377
'meta' => '{"BcCustomContent":{"email_confirm":"","max_file_size":"1","file_ext":"true"}}',
377378
'regex' => '[0-9]'
@@ -472,23 +473,21 @@ public function test_setValidateFileExt()
472473
{
473474
$validator = $this->CustomEntriesTable->getValidator('default');
474475
$customLink = CustomLinkFactory::make(['name' => 'test'])->getEntity();
475-
$customField = CustomFieldFactory::make()->getEntity();
476+
$customField = CustomFieldFactory::make(['type' => 'BcCcFile'])->getEntity();
476477
/**
477478
* file_ext is null
478479
*/
479480
$customField->meta = ['BcCustomContent' => ['file_ext' => null]];
480481
$customLink->custom_field = $customField;
481482
$rs = $this->CustomEntriesTable->setValidateFileExt($validator, $customLink);
482-
//check result return
483-
$this->assertArrayNotHasKey('test', $rs);
483+
$this->assertEquals(['gif', 'jpg', 'jpeg', 'png', 'pdf'], $rs['test']->rule('fileExt')->get('pass')[0]);
484484
/**
485485
* file_ext is not null
486486
*/
487487
$customField->meta = ['BcCustomContent' => ['file_ext' => 'jpg,png,gif']];
488488
$customLink->custom_field = $customField;
489489
$rs = $this->CustomEntriesTable->setValidateFileExt($validator, $customLink);
490-
//check result return
491-
$this->assertArrayHasKey('test', $rs);
490+
$this->assertEquals(['jpg', 'png', 'gif'], $rs['test']->rule('fileExt')->get('pass')[0]);
492491
/**
493492
* check message return
494493
* after when setValidateFileExt

0 commit comments

Comments
 (0)