Collection Type Field with a File Field to generate their own respective download link - forms

I having a problem with getting/generating the download link from a Collection Type Field in a form, inside the collection type I have a File Field. Everything works fine with uploading files but in order to generate their own respective download link is where I'm stucked right now.
Is there any way to get the url from the file field? What can I do?
<ul>
<li><ul class="preguntas" data-prototype="{{ form_widget(form.seguimientos.vars.prototype)|e }}">
{% for pregunta in form.seguimientos %}
<li>
{{ form_row(pregunta.seguimientoTipo) }}
{{ form_row(pregunta.fecha_entrega) }}
{{ form_row(pregunta.fecha_prorroga) }}
{{ form_row(pregunta.descripcion) }}
{{ form_row(pregunta.loQueSeEspera) }}
{{ form_row(pregunta.isRecibido) }}
{{ form_row(pregunta.contactos) }}
{{ form_row(pregunta.comentarios) }}
{{ form_row(pregunta.archivo) }}
</li>
{% endfor %}
</ul></li>
This is what I got with {{ dump(pregunta.archivo.vars.value) }}
object(Proxies\__CG__\daci\contratosBundle\Entity\Document)#596 (5) { ["__isInitialized__"]=> bool(true) ["id":protected]=> int(160) ["path":protected]=> string(44) "1feb865f404cba0567e075c76bf6c0b402621e8e.png" ["file":"daci\contratosBundle\Entity\Document":private]=> NULL ["temp":"daci\contratosBundle\Entity\Document":private]=> NULL }
What I want to get is "path" from the object and create the download link

To access to the field I just needed to use {{ pregunta.archivo.value.path }}
From that I created the download link

Related

Is there a way to yield to variable section in statamic?

I have a layout with several identical columns which should yield to respective sections:
<div class="column_1">
some column content here
{{ yield:column_1 }}
some more column stuff
</div>
<div class="column_2">
some column content here
{{ yield:column_2 }}
some more column stuff
</div>
...
Now I would like to put that into its own partial:
****** LAYOUT ******
{{ partial:column column_name="column_1" }}
{{ partial:column column_name="column_2" }}
...
****** PARTIALS/COLUMN.HTML ******
<div class="{{ column_name }}">
some column content here
{{ yield to-section="{column_name}" }}
some more column stuff
</div>
****** TEMPLATE *****
{{ section:column_1 }} **Additional stuff for column 1** {{ /section:column_1 }}
{{ section:column_2 }} **Additional stuff for column 2** {{ /section:column_2 }}
But in the documentation I can only find the colon syntax {{ yield:section }} and no hint to a possible variable syntax {{ yield unknown_word_here="section" }}. Most tags have a variable syntax, so I am hoping there is one. Or another solution...
I believe you're looking for the Section tag, which pairs nicely with the Yield tag.

Properly set Symfony's form error rendering position

I try to make a registration form in Symfony 3.4 but it makes me mad that I cannot place errors properly.
This is how I render the form itself:
{{ form_start(registrationForm) }}
{{ form_widget(registrationForm) }}
{{ form_end(registrationForm) }}
And the fields are rendered from a custom template, where I declare that errors should appear under the field:
{% block form_row %}
<div class="form-group">
{{ block('form_label') }}
{{ block('form_widget_simple') }}
{{ block('form_error') }}
</div>
{% endblock %}
However all my errors are appearing above the whole form as li elements in an ul element. I tried to add 'error_bubbling' => false but it won't make any difference. (The error messages come form the Assert annotations on the underlying model object.)
What am I doing wrong?

symfony2 and twig: get properties of form field

I am trying to create a form with sub-fields with symfony2.
In twig I render the form as
{{ form_start(form) }}
{{ form_errors(form) }}
<div>
{{ form_label(form) }}
{{ form_errors(form) }}
{% for field in form %}
{{ form_widget(field) }}
{% endfor %}
</div>
{{ form_end(form) }}
However, I want to add some customization depending on the field I am rendering.
What I want to achieve is something like this:
{{ form_start(form) }}
{{ form_errors(form) }}
<div>
{{ form_label(form) }}
{{ form_errors(form) }}
{% for field in form %}
{% if field.label == "myvalue" %} <-- this code is not working
{# do something here #}
{{ form_widget(field) }}
{% endif %}
{% endfor %}
</div>
{{ form_end(form) }}
I am not able to access the label of each of my sub-fields in twig.
I think it is possible with something like
{{ field.vars.something }}
, but I did not manage to find any clear documentation about this.
Can someone please help?
Thank you!
Edit:
I actually found the answer to my question:
It was indeed just
{{ field.vars.label }}
and
{% if field.vars.label == "myvalue" %}
{# do something here #}
{{ form_widget(field) }}
{% endif %}
did the trick.
However, I am still looking for some good documentation about this "vars" attribute in twig, and what can be retrieved with it.
Thanks!
You'll find more information at http://symfony.com/doc/current/reference/forms/twig_reference.html#more-about-form-variables
On that page you'll find a list of common form vars. You might also create custom vars by implementing the buildView method of a FormType. You can read an example at http://symfony.com/doc/current/cookbook/form/create_form_type_extension.html#adding-the-extension-business-logic
Hope it'll help

prototype field is empty after form(form) but set when set before the form(form) symfony

when I follow this tutorial: http://symfony.com/doc/current/cookbook/form/form_collections.html
and I render the
<ul class="tags" data-prototype="{{ form_widget(form.tags.vars.prototype)|e }}">
...
</ul>
the prototype stay empty if I put it after the {{ form(form)}} but gets filled If I put it i before the {{ form(form) }} tag. any one an idea why this is and how to solve it.
thanks
The tag {{ form(form) }} is supposed to output all your form, so there is nothing to output after this tag.
If the tag {{ form(form) }} does not output the prototype, then it was not configured right in the form type class.
But if you chose to output prototype by using form_widget, you should not use form(form) and should output the form by parts:
{{ form_start(form) }}
{{ form_errors(form) }}
<div>
{{ form_row(form.another_form_property) }}
</div>
<div>
<ul class="tags" data-prototype="{{ form_widget(form.tags.vars.prototype)|e }}">
...
</ul>
</div>
{{ form_end(form) }}

FOSUserBundle issues with plainPassword on twig form

I am defining my own twig layout for new user registration and I have everything laid out the way I want it with the exception of the plainPassword field from the FOSUserBundle.
<p class="left">
{{ form_widget(form.plainPassword) }}
</p>
<div class="clearfix"></div>
The code above displays both the password and verification block. I would like to break this up into the 4 elements of form.plainPassword.label, form.plainPassword.field, form.plainPassword2.label, and form.plainPassword2.field. I cannot figure out what to put in the form_label() and form_widget() calls.
<p class="left">
{{ form_label( ??? ) }}
{{ form_widget( ??? ) }}
</p>
<p class="left">
{{ form_label( ??? ) }}
{{ form_widget( ??? ) }}
</p>
<div class="clearfix"></div>
I am assuming this can be done.
I had the same problem. My solution (seems to be official :) :
{{ form_label (form.plainPassword.first) }}
{{ form_widget (form.plainPassword.first) }}
{{ form_label (form.plainPassword.second) }}
{{ form_widget (form.plainPassword.second) }}
Hope it can helps !
This blog post shows how to output a repeated field in twig.
http://blogsh.de/2011/10/19/how-to-use-the-repeated-field-type-in-symfony/
But in short this worked for me:
{{ form_label (form.plainPassword.children['New Password']) }}
{{ form_widget (form.plainPassword.children['New Password']) }}
{{ form_label (form.plainPassword.children['Confirm Password']) }}
{{ form_widget (form.plainPassword.children['Confirm Password']) }}
I have to say I'm sure using .children isnt the best/official way of doing it, but it works!