Skip to content

Commit

Permalink
フォームのファイルフィールドの問題を修正 (#2957)
Browse files Browse the repository at this point in the history
  • Loading branch information
seto1 authored Dec 20, 2023
1 parent 611448a commit b23715c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
5 changes: 5 additions & 0 deletions plugins/baser-core/src/Utility/BcFileUploader.php
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,11 @@ public function moveFileSessionToTmp($data, $fieldName)
$uploadInfo['uploadable'] = true;
$uploadInfo['ext'] = BcUtil::decodeContent($fileType, $fileName);
$uploadedFile[$fieldName] = $uploadInfo;

// 一時ファイルを一度に複数扱う場合に1ファイルしかアップロードされない問題への対応
// 例: メールフォームのファイルフィールドなど
$uploadedFile = array_merge($this->getUploadingFiles($data['_bc_upload_id']), $uploadedFile);

$this->setUploadingFiles($uploadedFile, $data['_bc_upload_id']);
return true;
}
Expand Down
4 changes: 4 additions & 0 deletions plugins/baser-core/src/View/Helper/BcUploadHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,10 @@ public function fileLink($fieldName, $entity, $options = [])
$basePath = '/baser-core/uploads/tmp/';
}

if (is_array($value)) {
return false;
}

/* ファイルのパスを取得 */
/* 画像の場合はサイズを指定する */
if (isset($settings['saveDir'])) {
Expand Down
13 changes: 6 additions & 7 deletions plugins/bc-mail/src/Service/MailMessagesService.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,13 @@ public function getIndex(array $queryParams = [])
*/
public function create(EntityInterface $mailContent, $postData)
{
if (!$postData instanceof EntityInterface) {
// newEntity() だと配列が消えてしまうため、エンティティクラスで直接変換
$entity = new MailMessage($postData, ['source' => 'BcMail.MailMessages']);
} else {
$entity = $postData;
$entity = $this->MailMessages->newEntity($postData);
foreach ($postData as $postKey => $postValue) {
if (is_array($postValue)) {
$entity->$postKey = $postValue;
}
}
$validateEntity = $this->MailMessages->patchEntity($this->MailMessages->newEmptyEntity(), $entity->toArray());
if (!$validateEntity->getErrors()) {
if (!$entity->getErrors()) {
$mailFieldsTable = TableRegistry::getTableLocator()->get('BcMail.MailFields');
$mailFields = $mailFieldsTable->find()->where(['MailFields.mail_content_id' => $mailContent->id, 'MailFields.use_field' => true])->all();
$this->MailMessages->convertToDb($mailFields, $entity);
Expand Down

0 comments on commit b23715c

Please sign in to comment.