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

  • SEARCH
  • Home
  • 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 7541091
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T07:48:14+00:00 2026-05-30T07:48:14+00:00

I need some help with prototypes that are within prototypes. Symfony is very clever

  • 0

I need some help with prototypes that are within prototypes. Symfony is very clever with generating form prototypes, but once you are one layer down (i.e. prototypes within prototypes), it reuses $$name$$ for both prototypes.

This is what a prototype field looks like for my entity. JQuery swaps out $$name$$ with the correct index value (based on number of child nodes)

 <input type="text" id="entry_entities_$$name$$_contactFax" name="entry[entities][$$name$$][contactFax]" value="" />

So far so good. But when you go one level deeper, Symfony uses $$name$$ for the next level down too – here is a prototype for the entity property:

<div id="entry_entities_123_properties" data-prototype="    
    &lt;label for=&quot;entry_entities_$$name$$_properties_$$name$$_name&quot;&gt;Name&lt;/label&gt;
    &lt;input type=&quot;text&quot; id=&quot;entry_entities_$$name$$_properties_$$name$$_name&quot; name=&quot;entry[entities][$$name$$][properties][$$name$$][name]&quot; value=&quot;&quot; /&gt;

This means that (in this example with entity id 123) that all properties get ID 123:

name="entry[entities][123][properties][123][name]"
name="entry[entities][123][properties][123][name]"
name="entry[entities][123][properties][123][name]"

etc.

In my opinion the best way to solve the issue would be to use $$somethingelse$$ for the property – does anyone know where this is set – or does anyone have a complete example with JS on how to solve this? I embarked on a horrible find/replace of the second $$name$$ on each line, but it got very messy. I’m sure there is an easy way to do this, but I couldn’t find any guides on the internet.

  • 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-05-30T07:48:16+00:00Added an answer on May 30, 2026 at 7:48 am

    This code is for symfony 2.0 (in 2.1+ you can just pass the name to prototype() function):

    You can create your own collection type with your required option:

    <?php
    
    namespace YourBundle\Form\Type;
    
    use Symfony\Component\Form\AbstractType;
    use Symfony\Component\Form\FormBuilder;
    use Symfony\Component\Form\FormView;
    use Symfony\Component\Form\FormInterface;
    use Symfony\Component\Form\Extension\Core\EventListener\ResizeFormListener;
    use Symfony\Component\Form\Extension\Core\Type\CollectionType as BaseCollectionType;
    
    class CollectionType extends BaseCollectionType
    {
        /**
         * {@inheritdoc}
         */
        public function buildForm(FormBuilder $builder, array $options)
        {
            if ($options['allow_add'] && $options['prototype']) {
                $prototype = $builder->create($options['prototype_name'], $options['type'], $options['options']);
                $builder->setAttribute('prototype', $prototype->getForm());
            }
    
            $listener = new ResizeFormListener(
                $builder->getFormFactory(),
                $options['type'],
                $options['options'],
                $options['allow_add'],
                $options['allow_delete']
            );
    
            $builder
                ->addEventSubscriber($listener)
                ->setAttribute('allow_add', $options['allow_add'])
                ->setAttribute('allow_delete', $options['allow_delete'])
            ;
        }
    
        /**
         * {@inheritdoc}
         */
        public function getDefaultOptions(array $options)
        {
            $defaultOptions = parent::getDefaultOptions($options);
            $defaultOptions['prototype_name'] =  '$$name$$';
            return $defaultOptions;
        }
    }
    

    Then just define a service with:

    tags:
        - { name: form.type, alias: collection }
    

    And use it as Symfony’s collection but with prototype_name parameter.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Need some help, please. I have a line of horizontal thumbnails loaded as ONE
Need some help from javascript gurus. I have one page where http://www.google.com/finance/converter is embedded
Need some help assigning a mouseover event to display some icons that start out
Need some help with the CSS for generating a grid of perfect squares. Div's
need some help! I'm trying to write some code in objective-c that requires part-of-speech
Need some help refactoring this if/else block that builds the conditions for a find
need some help with a MYSQL call. In one of my tables, I have
Need some help with a regular expression How can I write an expression that
need some help with this one. I have some reflectance values for a colour
Need some help. I am able to print pdf & images directly but 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.