question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

New Symfony 2.8 change: form field types are class names

See original GitHub issue

Hi there!

I ❤️ this plugin, and I usually if something isn’t up to date, it suddenly is a few days later!

For Symfony 2.8, the form types have changed from being a string (e.g. text) to being a full class name:

// before
$builder->add('username', 'text');
// after
$builder->add('username', TextType::class);

In PhpStorm itself, the only unfortunate thing is that typing TextType does not bring up the TextType class as an auto-complete suggestion, because it has no static methods/constants/properties. So, you need to type TextType::class, and then go back and “Import class” to add the use statement. Ideally - if this is possible - it would auto-complete known classes that implement FormTypeInterface in the project.

If I can help with this, I’d be happy to assist.

Thanks!

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
hoshsadiqcommented, Dec 25, 2015

Sorry to open an older ticket, but the same is the case for other sitations:

  • from in QueryBuilder (probably other things too):

    $qb = new QueryBuilder($em);
    $qb->select('t')->from(MyEntity::class, 't');
    
  • Additionally the above, doesn’t provide further autocomplete:

    $qb = new QueryBuilder($em);
    $qb->select('t')->from(MyEntity::class, 't')
    ->leftJoin('t.someField', 'sf'); // if you use MyEntity::class it doesn't provide autocomplete for someField, but if you use the currently support ways, it does. The same is the case in other statements such as where etc.
    
  • EntityType::class type in the option class:

    $builder->add(
        'someRelations',
        'entity',
        array(
            'class' => SomeRelation::class
        )
    );
    
  • EntityManager::getReference():

    $this->entityManager->getReference(MyEntity::class, $id);
    
  • OptionsResolver::setAllowedTypes:

    $resolver->setAllowedTypes('em', ObjectManager::class);
    
  • Final one I could find is in doctrine queries themselves:

    $em->createQuery('SELECT t FROM '.MyEntity::class.' t');
    
0reactions
hoshsadiqcommented, Jun 10, 2016

Aah damn, I was meant to raise a new issue with that as this one is closed. Totally forgot.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Create a Custom Form Field Type (Symfony 2.8 Docs)
Defining the Field Type. In order to create the custom field type, first you have to create the class representing the field. In...
Read more >
How to Customize Form Rendering (Symfony 2.8 Docs)
The product portion of the field is the form name, which may be set manually or generated automatically based on your form type...
Read more >
FormType Field (Symfony Docs)
Allows you to add a custom block name to the ones used by default to render the form type. Useful for example if...
Read more >
How to Customize Form Rendering (Symfony Docs)
In this article you'll learn how to make single customizations to one or more fields of your forms. If you need to customize...
Read more >
Forms (Symfony Docs)
Passing Options to Forms; Form Type Options; Changing the Action and HTTP Method; Changing the Form Name; Client-Side HTML Validation; Form Type Guessing ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found