Skip to content
Permalink
Browse files

Merge pull request #4235 from kazumiiiiiiiiiii/file_management_multip…

…le_upload

ファイル管理で複数ファイルのアップロードを実装
  • Loading branch information...
chihiro-adachi committed Aug 6, 2019
2 parents 60f34a5 + 9c9a34f commit fe5cae800fa4e7f09cbb905e1ef3632b34e41489
@@ -55,7 +55,12 @@ public function __construct()
public function index(Request $request)
{
$form = $this->formFactory->createBuilder(FormType::class)
->add('file', FileType::class)
->add('file', FileType::class, [
'multiple' => true,
'attr' => [
'multiple' => 'multiple'
],
])
->add('create_file', TextType::class)
->getForm();
@@ -132,7 +137,12 @@ public function view(Request $request)
public function create(Request $request)
{
$form = $this->formFactory->createBuilder(FormType::class)
->add('file', FileType::class)
->add('file', FileType::class, [
'multiple' => true,
'attr' => [
'multiple' => 'multiple'
],
])
->add('create_file', TextType::class, [
'constraints' => [
new Assert\NotBlank(),
@@ -238,6 +248,7 @@ public function upload(Request $request)
{
$form = $this->formFactory->createBuilder(FormType::class)
->add('file', FileType::class, [
'multiple' => true,
'constraints' => [
new Assert\NotBlank([
'message' => 'admin.common.file_select_empty',
@@ -263,16 +274,29 @@ public function upload(Request $request)
if (!$this->checkDir($nowDir, $topDir)) {
$this->errors[] = ['message' => 'file.text.error.invalid_upload_folder'];
return;
}
$filename = $this->convertStrToServer($data['file']->getClientOriginalName());
try {
$data['file']->move($nowDir, $filename);
$this->addSuccess('admin.common.upload_complete', 'admin');
} catch (FileException $e) {
$this->errors[] = ['message' => $e->getMessage()];
$uploadCount = count($data['file']);
$successCount = 0;
foreach ($data['file'] as $file) {
$filename = $this->convertStrToServer($file->getClientOriginalName());
try {
$file->move($nowDir, $filename);
$successCount ++;
} catch (FileException $e) {
$this->errors[] = ['message' => trans('admin.content.file.upload_error', [
'%file_name%' => $filename,
'%error%' => $e->getMessage()
])];
}
}
if ($successCount > 0) {
$this->addSuccess(trans('admin.content.file.upload_complete', [
'%success%' => $successCount,
'%count%' => $uploadCount
]), 'admin');
}
}
@@ -939,6 +939,8 @@ admin.content.file.directory_name: Folder Name
admin.content.file.file_list__card_title: Files in This Directory
admin.content.file.updated: Update
admin.content.file.directory_tree: Directories
admin.content.file.upload_complete: %success% file upload completed. (%success%/%count%)
admin.content.file.upload_error: Failed to upload %file_name%. (%error%)
admin.content.layout_delete: Delete Layouts
admin.content.layout_no_page: Page not registered
admin.content.layout__card_title: Layout Overview
@@ -1527,6 +1529,7 @@ tooltip.customer.purchase_history: Order history of this customer is displayed h
tooltip.customer.shop_memo: Notes for store use. This will not be displayed on the storefront.
tooltip.content.news.url: If there is a page which provides the details of this news, enter its URL. You can also enter external URLs.
tooltip.content.news.body: You can use HTML tags.
tooltip.content.file.upload_file: You can select multiple files and upload files.
tooltip.content.layout_edit: You can drag & drop blocks for each template sections.
tooltip.content.page_file_name: This is the name of a twig template file which has the page contents.
tooltip.content.page_source_code: Editing the template file. Coding has to be with twig.
@@ -939,6 +939,8 @@ admin.content.file.directory_name: フォルダ名
admin.content.file.file_list__card_title: このフォルダ内のファイル
admin.content.file.updated: 更新
admin.content.file.directory_tree: フォルダ構成
admin.content.file.upload_complete: %success%件のファイルをアップロードしました。(%success%/%count%)
admin.content.file.upload_error: %file_name% のアップロードに失敗しました。(%error%)
admin.content.layout_delete: レイアウトを削除
admin.content.layout_no_page: ページが登録されていません
admin.content.layout__card_title: レイアウト概要
@@ -1527,6 +1529,7 @@ tooltip.customer.purchase_history: この会員が注文をした履歴が表示
tooltip.customer.shop_memo: 店舗用のメモ欄です。フロント側には表示されません。
tooltip.content.news.url: この新着情報の詳細な内容を記したウェブページある場合、URLを入力します。外部サイトのURLなどを利用することもできます。
tooltip.content.news.body: HTMLタグが利用可能です。
tooltip.content.file.upload_file: ファイルの追加は複数ファイルを選択してアップロードできます。
tooltip.content.layout_edit: テンプレートのセクションごとにブロックをドラッグ&ドロップで配置することができます。
tooltip.content.page_file_name: ページの内容を記述したtwigテンプレートファイルの名前です。
tooltip.content.page_source_code: テンプレートファイルを編集します。twigで記述します。
@@ -112,7 +112,7 @@ file that was distributed with this source code.
<div class="card-header"><span class="card-title">{{ 'admin.content.file.add_file__card_title'|trans }}</span></div>
<div class="card-body">
<div id="upload_box__file" class="row mb-2">
<div class="col-2"><span>{{ 'admin.content.file.add_file'|trans }}</span></div>
<div class="col-2" data-tooltip="true" data-placement="top" title="{{ 'tooltip.content.file.upload_file'|trans }}"><span>{{ 'admin.content.file.add_file'|trans }}</span><i class="fa fa-question-circle fa-lg ml-1"></i></div>
<div class="col mb-3">
<div class="mb-2">
{{ form_widget(form.file) }}{# TODO input type="file" の装飾 #}
@@ -94,35 +94,48 @@ public function testIndexWithCreate()
public function testIndexWithUpload()
{
$filepath = $this->getUserDataDir().'/../aaa.html';
$contents = '<html><body><h1>test</h1></body></html>';
file_put_contents($filepath, $contents);
$filepath1 = $this->getUserDataDir().'/../aaa.html';
$contents1 = '<html><body><h1>test1</h1></body></html>';
file_put_contents($filepath1, $contents1);
$file = new UploadedFile(
realpath($filepath), // file path
$filepath2 = $this->getUserDataDir().'/../bbb.html';
$contents2 = '<html><body><h1>test2</h1></body></html>';
file_put_contents($filepath2, $contents2);
$file1 = new UploadedFile(
realpath($filepath1), // file path
'aaa.html', // original name
'text/html', // mimeType
null, // file size
null, // error
true // test mode
);
$file2 = new UploadedFile(
realpath($filepath2), // file path
'bbb.html', // original name
'text/html', // mimeType
null, // file size
null, // error
true // test mode
);
$crawler = $this->client->request(
'POST',
$this->generateUrl('admin_content_file'),
[
'form' => [
'_token' => 'dummy',
'create_file' => '',
'file' => $file,
'file' => [$file1, $file2],
],
'mode' => 'upload',
'now_dir' => '/',
],
['file' => $file]
['file' => [$file1, $file2]]
);
$this->assertTrue($this->client->getResponse()->isSuccessful());
$this->assertTrue(file_exists($this->getUserDataDir().'/aaa.html'));
$this->assertTrue(file_exists($this->getUserDataDir().'/bbb.html'));
}
protected function getUserDataDir()

0 comments on commit fe5cae8

Please sign in to comment.
You can’t perform that action at this time.