In my project, I have pages and elements related to them. An item can only be associated with one page.
I have a specific form for selecting a field mask and many fields. I would like to have a list of elements related to the page, not the embedded forms. Is it possible to open a modal dialog to have an edit form in it, for example, when you add an element?
Is sonata_type_collection the most suitable for this?
PageAdmin protected function configureFormFields(FormMapper $formMapper) { $availableApiRoutes = []; foreach ($this->getConfigurationPool()->getContainer()->get('router')->getRouteCollection()->all() as $name => $route) { $route = $route->compile(); if (( strstr($name, "api_") === FALSE ) && ( strstr($name, "admin") === FALSE ) && ( strstr($name, "ajax") === FALSE ) && ( strstr($name, "fos") === FALSE ) && ( strstr($name, "sonata") === FALSE ) && ( strstr($name, "add") === FALSE ) && ( strstr($name, "edit") === FALSE ) && ( strstr($name, "payment") === FALSE ) && ( strstr($name, "suppr") === FALSE ) && ( substr($name, 0, 1) !== "_" )) { $availableApiRoutes[$name] = $name; } } $formMapper ->add('route', FormType\ChoiceType::class , array( 'choices' => $availableApiRoutes, )) ->add('element', 'sonata_type_collection', array(), array('edit' => 'inline', 'inline'=>'table')) ; }
And the shape of the element:
ElementAdmin protected function configureFormFields(FormMapper $formMapper) { $formMapper ->add('page', 'sonata_type_model_hidden') ->add('id') ->add('title') ->add('type', 'sonata_type_choice_field_mask', array( 'choices' => array( 'texte' => 'texte', 'image' => 'image', 'gallery' => 'gallerie' ), 'map' => array( 'texte' => array('texte'), 'image' => array('image'), 'gallery' => array('gallery'), ), 'empty_value' => 'Choose an option', 'required' => true )) ->add('texte', CKEditorType::class, array( 'config' => array( 'uiColor' => '#ffffff' ) )) ->add('image', 'sonata_type_model_list', array(), array('link_parameters' => array('context' => 'cms'))) ->add('gallery', 'sonata_type_model_list', array(), array( 'edit' => 'inline', 'inline' => 'table', 'link_parameters' => array( 'context' => 'cms', 'provider' => 'sonata.media.provider.image' ) )) ; }