sonata block : Could not load type "entity"

480 views
Skip to first unread message

Stephane Alamichel

unread,
Jul 29, 2016, 12:52:08 PM7/29/16
to sonata-users
Dear all,

I have an issue that i do not understand how to figure out.

I would like to put a form view into a blockService to put on the dashboard.

I have a formType as this :

class GoogleMapType extends AbstractType {

public function buildForm(FormBuilderInterface $builder, array $options) {
...
->add('adoptant', 'entity', array(
'class' => 'acmeBundle:Persons\Adoptant',
'query_builder' => function (AdoptantRepository $ar) {
return $ar->queryFindAll();
},
'multiple' => true,
'required' => false,
))
...

My block Service is like this

class GoogleMapsBlockService extends BaseBlockService {

    public function __construct($type, $templating) {
        $this->type = $type;
        $this->templating = $templating;
    }

    public function getName() {
        return 'googleMaps';
    }

    public function getDefaultSettings() {
        return array();
    }

    public function validateBlock(ErrorElement $errorElement, BlockInterface $block) {
        
    }

    public function buildEditForm(FormMapper $formMapper, BlockInterface $block) {
        
    }

    public function execute(BlockContextInterface $blockContext, Response $response = null) {
        $settings = array_merge($this->getDefaultSettings(), $blockContext->getBlock()->getSettings());

        $formFactory = Forms::createFormFactory();

        $form = $formFactory->create(new GoogleMapType());

        return $this->renderResponse('AcmeBundle:Block:GoogleMaps.html.twig', array(
                    'block' => $blockContext->getBlock(),
                    'settings' => $settings,
                    'form' => $form->createView(),
                        ), $response);
    }

}


When I "plug" the blockservice into sonata admin configuration i have this error

"An exception has been thrown during the rendering of a template ("Could not load type "entity"") in SonataAdminBundle:Core:dashboard.html.twig at line 24."

It's work correctly if there are not 'entity' type into the formType.

Please do you know how to push formtype with entity type ?

Regards
ps : thanks a lot for this project !




Cassiano Tartari

unread,
Jul 29, 2016, 1:14:26 PM7/29/16
to sonata-users
Which symfony version are you using? Because could be "EntityType::class" instead of "entity"

Att.,
Cassiano Tartari

--
You received this message because you are subscribed to the Google Groups "sonata-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sonata-users...@googlegroups.com.
To post to this group, send email to sonata...@googlegroups.com.
Visit this group at https://groups.google.com/group/sonata-users.
For more options, visit https://groups.google.com/d/optout.

Stephane Alamichel

unread,
Jul 29, 2016, 1:40:03 PM7/29/16
to sonata...@googlegroups.com
Hi, I'm using Sf 2.8, and Sonata 2.3x

I have already try to put "EntityType::class" in the formType file, I have the same issue

An exception has been thrown during the rendering of a template ("Could not load type "EntityType::class"")



--
You received this message because you are subscribed to a topic in the Google Groups "sonata-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sonata-users/PG-gSsp5YQo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sonata-users...@googlegroups.com.

Cassiano Tartari

unread,
Jul 29, 2016, 1:41:47 PM7/29/16
to sonata-users

2016-07-29 14:39 GMT-03:00 Stephane Alamichel <stephane....@gmail.com>:
An exception has been thrown during the rendering of a template ("Could not load type "EntityType::class"")

​And you've added "use Symfony\Bridge\Doctrine\Form\Type\EntityType​;" ?


Att.,
Cassiano Tartari

Stephane Alamichel

unread,
Jul 29, 2016, 1:44:32 PM7/29/16
to sonata...@googlegroups.com
yes also, i'm going crazy.

--

Stephane Alamichel

unread,
Jul 29, 2016, 1:48:30 PM7/29/16
to sonata...@googlegroups.com
My forms works perfectly when I used standard controller/view rendering.

But when I want to put into a block service, everything goes wrong.

It seems that the error is trigger when " $formFactory->create(new GoogleMapType());" is evaluated


public function execute(BlockContextInterface $blockContext, Response $response = null) {
        $settings = array_merge($this->getDefaultSettings(), $blockContext->getBlock()->getSettings());

        $formFactory = Forms::createFormFactory();

        $form = $formFactory->create(new GoogleMapType());

        dump($form);// HERE NOT TRIGGERED

        return $this->renderResponse('ApparRefugeBundle:Block:GoogleMaps.html.twig', array(
                    'block' => $blockContext->getBlock(),
                    'settings' => $settings,
                    'form' => $form->createView(),
                        ), $response);
    }

Simon Ball

unread,
Aug 7, 2016, 2:07:57 AM8/7/16
to sonata-users
I just want to check as I see you are trying to use the GoogleMapType in the current namespace, you have a use statement for the appropriate Type?

A different approach if specifically complaining about the form type could be to create it as a service.
Reply all
Reply to author
Forward
0 new messages