Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9037869
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T09:20:50+00:00 2026-06-16T09:20:50+00:00

I need help with this since I just can’t figure it out by myself

  • 0

I need help with this since I just can’t figure it out by myself even after reading and examining all resources I found on the internet.

I have an Image entity. It has 3 mapped properties.

  1. id
  2. location
  3. thumb_location

And I have custom ImageSelectType form type which extends AbstractType:

buildForm function looks like this:

public function buildForm(FormBuilderInterface $builder, array $options)
{
    $em = $options['em'];

    $qb = $em->createQueryBuilder();
    $result = $qb->select('i')
            ->from('BloggerBlogBundle:Image', 'i')
            ->leftJoin('i.articles', 'a')
            ->where('a is NULL')
            ;

    $builder
        ->add('images', 'entity', array(
                'class' => 'BloggerBlogBundle:Image',
                'query_builder' => $result,
                                    'required' => true,
                                    'multiple' => false,
                                    'expanded' => true,
            )
        )
                        ->setAttribute('widget', 'imageSelect')
        ;
}

So it takes all images that aren’t used by any article and populates form with them. With these options, I get radiobuttons, like this:

<div id="image_images">
    <input type="radio" id="image_images_67" name="image[images]" required="required" value="67"><label for="image_images_67" class="required">c5252b4ffc9c50540218e25be1353b33aaa4ee05.png</label>
    <input type="radio" id="image_images_68" name="image[images]" required="required" value="68"><label for="image_images_68" class="required">fcfc7d7d05d63b1f55dff8cbff0bedeb3c917dfc.jpeg</label>
</div>

What I want now is all radiobuttons to have custom html5 data attribute data-thumb="thumbnail/location.png" which would be the thumb_location property value of image object represented by that radiobutton.

I hope I was clear enough. If any more info is needed I will provide it.
I’ve read so much about this but I think I’m imagining things more complex then they actually are. At one point I just wanted to say ‘Oh, forget it, I’ll just render this manually’ and use:

{% for choice in form.vars.choices %}
    <input type="radio" data-thumb="{{choice.thumb_location}}" />
{% endfor %}

But I really want to use good practices that this amazing framework provides….Sometimes just don’t seem as obvious to me as they should.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T09:20:51+00:00Added an answer on June 16, 2026 at 9:20 am

    Ah, I thought this was relating to this object as the FormType is. So in this case I see the possibility to set a variable withe the buildView method.

     /**
     * {@inheritdoc}
     */
    public function buildView(FormView $view, FormInterface $form, array $options)
    {
         $view->vars['thumb'] = $options['thumb'];
    }
    

    You can set this option whether in the ->add(x, x, array(‘thumb_location’ => ‘location’))
    (or in the setDefaultOptions method).

    But now I am not sure to be honest. Because you would need to set in the view like this:

    <input data-thumb="{{ thumb }}" type="radio" id="blog_article_image_17" name="blog_article[image]" required="required" value="17">
    

    And this means you make <input data... by hand again.

    Not sure if this is possible in your case but I think it would be nice to define a second FormType for the radio input field:

    public function buildForm(FormBuilderInterface $builder, array $options)
    {
       ...this is your current form builder....
    
       ->add('radio', MyRadioType());
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sheesh... I think this can be done but I just can't figure it out
It's been one of those days and I just can't figure this out. I
I need some help with this, since it baffles me in my C program
I'm having an issue that I just can't seem to figure out. I built
I don't want code, just need help finding where to start this project. I
I really need help this time - Joomla 2.5 and latest K2. I'm using
i need help with this. I'am using JQuery's Dynamic Form plug-in, it duplicates my
I need help finishing this statement. It is frustrating that two of the PHP
I really need help with this last part of my program. I need to
I Really need help in this ... I'm building an application where I need

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.