-1

Is this really necessary to use all these Types (even much more..) itemised? Isn't there one "use" for forms that summarize them all?

use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\ButtonType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\NumberType;
use Symfony\Component\Form\Extension\Core\Type\DateType;
use Symfony\Component\Form\Extension\Core\Type\MoneyType;
use Symfony\Component\Form\Extension\Core\Type\BirthdayType;
peace_love
  • 6,229
  • 11
  • 69
  • 157
  • all of them extend from `Symfony\Component\Form\Extension\Core\Type\FormType` – yceruto Aug 06 '18 at 14:54
  • If it's just about the `use` statements you can instead only use the parent namespace (up until Type) and then reference the specific type in your code starting from that point, for example: `Type\BirtdayType`. – dbrumann Aug 06 '18 at 15:01
  • @yceruto I tested only use `Symfony\Component\Form\Extension\Core\Type\FormType` instead, but then I get an error message for all types: `Could not load type "App\Controller\TextType": class does not exist` – peace_love Aug 06 '18 at 15:11
  • @dbrumann No, I was looking for just one line like `use Symfony\Component\Form\Extension\Core\Type\AllTypes` – peace_love Aug 06 '18 at 15:12
  • Maybe it can help you : https://stackoverflow.com/a/7121929/2454790 – BENARD Patrick Aug 06 '18 at 15:33
  • Can you show some code from the Extension? The solution from @yceruto sounds right. As described [in the docs (see comment in the code snippet)](https://symfony.com/doc/current/form/create_form_type_extension.html#defining-the-form-type-extension) you can use FormType as extended type and the extension should apply to (almost) all fields. – dbrumann Aug 06 '18 at 15:44
  • @dbrumann I worked with this tutorial: https://github.com/bradtraversy/symphart – peace_love Aug 06 '18 at 15:51
  • So when you say Form Extension, do you mean this: https://github.com/bradtraversy/symphart/blob/master/src/Controller/ArticleController.php#L35 because in that case you unfortunately used the name for a concept that means something else in Symfony, but I think it will make it easier to give a helpful answer. – dbrumann Aug 06 '18 at 18:17

1 Answers1

2

Its not possible to bulk include a namespace - possible solutions can be:

Grouped declarations - PHP 7+

use Symfony\Component\Form\Extension\Core\Type\{TextType,ButtonType,EmailType,HiddenType,PasswordType,TextareaType,SubmitType,NumberType,DateType,MoneyType,BirthdayType};

Use the parent namespace

use Symfony\Component\Form\Extension\Core\Type;

$type = new Type\HiddenType();

as from @dbrumann suggested

mthor
  • 46
  • 7