-
Notifications
You must be signed in to change notification settings - Fork 40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
UploadFileHelper - change api to support multiple files #40
Merged
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?php | ||
|
||
namespace Symfony\Cmf\Bundle\MediaBundle\Tests\Resources\Controller; | ||
|
||
use Symfony\Bundle\FrameworkBundle\Controller\Controller; | ||
use Symfony\Cmf\Bundle\MediaBundle\File\UploadFileHelper; | ||
use Symfony\Component\HttpFoundation\Request; | ||
|
||
class PhpcrFileTestController extends Controller | ||
{ | ||
public function getUploadForm($editor = null) | ||
{ | ||
if ($editor) { | ||
$action = $this->generateUrl('cmf_media_file_upload', array('editor' => $editor)); | ||
} else { | ||
$action = $this->generateUrl('phpcr_file_test_upload'); | ||
} | ||
|
||
return $this->container->get('form.factory')->createNamedBuilder(null, 'form', null, array('action' => $action)) | ||
->add('file', 'file') | ||
->add('submit', 'submit') | ||
->getForm() | ||
; | ||
} | ||
|
||
public function fileAction(Request $request) | ||
{ | ||
$fileClass = 'Symfony\Cmf\Bundle\MediaBundle\Doctrine\Phpcr\File'; | ||
$dm = $this->get('doctrine_phpcr')->getManager('default'); | ||
$files = $dm->getRepository($fileClass)->findAll(); | ||
|
||
$uploadForm = $this->getUploadForm(); | ||
$editorUploadForm = $this->getUploadForm('default'); | ||
|
||
return $this->render('::tests/file.html.twig', array( | ||
'upload_form' => $uploadForm->createView(), | ||
'editor_form' => $editorUploadForm->createView(), | ||
'files' => $files, | ||
)); | ||
} | ||
|
||
public function uploadAction(Request $request) | ||
{ | ||
$form = $this->getUploadForm(); | ||
$form->handleRequest($request); | ||
|
||
if ($form->isValid()) { | ||
/** @var UploadFileHelper $uploadFileHelper */ | ||
$uploadFileHelper = $this->get('cmf_media.upload_file_helper'); | ||
|
||
$uploadedFile = $request->files->get('file'); | ||
|
||
$file = $uploadFileHelper->handleUploadedFile($uploadedFile); | ||
|
||
// persist | ||
$dm = $this->get('doctrine_phpcr')->getManager('default'); | ||
$dm->persist($file); | ||
$dm->flush(); | ||
} | ||
|
||
return $this->redirect($this->generateUrl('phpcr_file_test')); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
This is a test file used to test uploads. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,24 @@ | ||
{% extends "::layout.html.twig" %} | ||
{% block content %} | ||
<h2>Download file</h2> | ||
<ul> | ||
{% for file in files %} | ||
<li><a href="{{ cmf_media_download_url(file) }}" title="Download {{ file.name }}">Download {{ file.name }}</a></li> | ||
{% endfor %} | ||
</ul> | ||
<h2>Upload file</h2> | ||
<h4>Standard upload</h4> | ||
<p>The upload is handled by your own controller action. The UploadFileHelper is used to handle the upload and creates a | ||
FileInterface object, writing the object to storage has to be implemented by yourself.</p> | ||
{{ form(upload_form, { attr: { class: 'standard' } }) }} | ||
<h4>Web editor upload (default)</h4> | ||
<p>The upload is completely handled by the FileController::uploadAction. The UploadFileHelper will process the upload, | ||
writes the created FileInterface object to storage and returns a response that depends on the editor defined in the | ||
request.</p> | ||
{{ form(editor_form, { attr: { class: 'editor default' } }) }} | ||
|
||
<h2>Download file(s)</h2> | ||
{% if files is empty %} | ||
<p>No files found, upload a file first.</p> | ||
{% else %} | ||
<ul class="downloads"> | ||
{% for file in files %} | ||
<li><a href="{{ cmf_media_download_url(file) }}" title="Download {{ file.name }}">Download {{ file.name }}</a></li> | ||
{% endfor %} | ||
</ul> | ||
{% endif %} | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
security: | ||
role_hierarchy: | ||
ROLE_ADMIN: [ROLE_USER, ROLE_CAN_UPLOAD_FILE] | ||
ROLE_SUPER_ADMIN: [ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH] |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if it is a good idea to refer to an "editor" here. Could we not use this upload thingy from a web form, or something else?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What use-case do you think about? Can you explain a bit more?
I think (atm) we are mostly going to automate the upload process for different web editors. And that otherwise the
handleUploadedFile
can be used for custom web forms were the response is created by yourself.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should check this later, added a note to the earlier created issue #34 so we do not forget.