Comments (11)
First of all i invite you to read : http://symfony2admingenerator.org/documentation/form-advanced.html#choose-your-types
You have to ways to overwrite the type of a field by php overwriting the build method or by yaml.
Yaml is more fun :D so in your yaml so write something like that :
edit:
fields:
text_type:
formType: choice
formOptions:
choices:
text: A simple text
html: With a html editor
Of course for file and wysiwyg its the same.
If your wysiwyg require js read :http://symfony2admingenerator.org/documentation/form.html#overwrite-the-rendering-of-a-field
from admingeneratorgeneratorbundle.
Thank for choices, this is what I need... Add in the documentation please.
For a file (preview_img) as I understand these steps:
-
Add a html to the template "NamespaceYourBundle: (Edit | New): index.html.twig"
{% block form_preview_img%}
{{parent ()}}{% endblock%} -
Overloaded method updateAction in EditController
???
from admingeneratorgeneratorbundle.
No for the file :
edit:
fields:
image:
formType: file
formOptions: []
And in updateAction
<?php
///....
public function updateAction($id)
{
//....
$this->saveObject(${{ builder.ModelClass }});
// Add this http://symfony.com/doc/current/reference/forms/types/file.html
$form['image']->getData()->move($dir, $someNewFilename);
$this->get('session')->setFlash('success', 'The object was successfully saved');
//....
}
I'll add a postSave($form, ${{ builder.ModelClass }})
method to ease overriding this action
If you want a preview :
{% block form_image %}
<div class="preview">
{% if MyModel.image %}
<img src="{{ MyModel.image }}" />
{% endif %}
</div>
{{ parent() }} {# parent() show the content of the autogenerated block #}
{% endblock %}
For the HTML editor :
{% block form_html %}
{{ parent() }}
<srcipt>
// The js to load the editor
</script>
{% endblock %}
from admingeneratorgeneratorbundle.
Thanks, I'll try your version
from admingeneratorgeneratorbundle.
I just add a postSave method
from admingeneratorgeneratorbundle.
Thank, tomorrow will try to use
from admingeneratorgeneratorbundle.
For file field i add uload method in my model (entity).
...
public function upload()
{
if(null != $this->preview_img){
$previewImgName = uniqid().'.'.$this->preview_img->guessExtension();
$this->preview_img->move($this->getUploadRootDir(), $previewImgName);
$this->preview_img = $previewImgName;
}
}
...
and overload updateAction in EditController:
...
if ($form->isValid()) {
$Text->upload();
$this->saveObject($Text);
$this->postSave($form, $Text);
can add method beforeSave(\Entity $val) before calling:
...
$this->beforeSave($Text);
$this->saveObject();
...
so i can immediately write to the database a new file name
from admingeneratorgeneratorbundle.
I have added a preSave()
method with the same signature than postSave()
but i think that you should move the picture only if there is non db exception on save()
so i recommend you to calculate the image path on preSave() and to move it on postSave()
from admingeneratorgeneratorbundle.
Thanks...
Another little problem, how to make a field file is not required?
from admingeneratorgeneratorbundle.
set the form option with the yaml parameter formOptions
or addFormOptions
with the parameter required: false
fields:
file:
addFormOptions:
required: false
from admingeneratorgeneratorbundle.
It works, i not properly declared 'require' property
from admingeneratorgeneratorbundle.
Related Issues (20)
- afe_single_upload riquiered issue HOT 6
- Doctrine ORM Manager named "default" does not exist. HOT 8
- Hardcoded id in getFilterForm HOT 2
- Excel export. Wont Work HOT 3
- Extend ExcelController from the user project ListController HOT 8
- Problem after upgrade to Symfony 2.6 HOT 1
- Problem Multi upload with single upload HOT 4
- ContextErrorException HOT 3
- GenerateAdminCommand compatible with SensioGeneratorBundle HOT 2
- updateRouting definition error with symfony 2.6 HOT 4
- Conflict with avocode/form-extensions-bundle HOT 6
- ListController::isCsrfTokenValid() changed and need 2 arguments HOT 1
- Init new tag v1.0.3 and v1.1.4 HOT 4
- Add uglifyjs and uglifycss support HOT 3
- Filters HOT 1
- Cumplidos sus requerimientos, NO logro descargar via composer...please check ! I very interesting!
- ser
- Global stopOnFail(true) should be overrideable with local stopOnFail HOT 2
- updateRouting() should be compatible HOT 1
- ODM is no longer supported HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from admingeneratorgeneratorbundle.