Discussion:
[sonata-users] inherit a sonata_type_collection class (i.e Sonata\CoreBundle\Form\Type\CollectionType)
et
2014-11-28 09:30:50 UTC
Permalink
Hello,

I would like to have a widget like sonata_type_collection, with this
widget, i have a row like this:

$formMapper->add('articles', 'sonata_type_collection', array(
'required' => true
,'by_reference' => false
,'label' => "AJOUTEZ DES ARTICLES :"
,'disabled' => $commande->estCommandeIssuDeDevis()
,'btn_add' => $commande->estCommandeIssuDeDevis() ? false : 'Ajouter un
article'
),
array(
'edit' => 'inline'
,'multiple' => true
,'expanded' => true
,'inline' => 'table'
,'allow_delete' => ! $commande->estCommandeIssuDeDevis()
,'admin_code' => 'sonata.admin.CommandeArticle'
)
);

child:
protected function configureFormFields(FormMapper $formMapper)
{
$formMapper
->add('Description', null, array(
'attr' => array('style' => 'width: 95%;')
))
->add('Quantite')
->add('article_taille', null, array(
'attr' => array('style' => 'width: 95%;')
))
;
}



<Loading Image...>


but i would like to have a line for each element of the select (already
selected)


I would like to modify this class, and use it normally:

- i replace 'sonata_type_collection' with 'mon_sonata_type_collection':

$formMapper->add('articles', 'mon_sonata_type_collection');

- add the inherited class into l3ia\Bundle\ERPBundle\Form\Type\
MonSonataCollectionType.php:

namespace l3ia\Bundle\ERPBundle\Form\Type;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormView;

use Symfony\Component\OptionsResolver\OptionsResolverInterface;

use Sonata\CoreBundle\Form\EventListener\ResizeFormListener;

class MonSonataCollectionType extends AbstractType
{
/**
* {@inheritDoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$listener = new ResizeFormListener(
$options['type'],
$options['type_options'],
$options['modifiable'],
$options['pre_bind_data_callback']
);

$builder->addEventSubscriber($listener);
}

/**
* {@inheritdoc}
*/
public function buildView(FormView $view, FormInterface $form, array
$options)
{
$view->vars['btn_add'] = $options['btn_add'];
$view->vars['btn_catalogue'] = $options['btn_catalogue'];
}

/**
* {@inheritDoc}
*/
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array(
'modifiable' => false,
'type' => 'text',
'type_options' => array(),
'pre_bind_data_callback' => null,
'btn_add' => 'link_add',
'btn_catalogue' => 'SonataCoreBundle'
));
}

/**
* {@inheritDoc}
*/
public function getName()
{
return 'mon_sonata_type_collection';
}
}

- add the service in file that there is other services that all works:

l3ia.form.type.mon_sonata_type_collection:
class: l3ia\Bundle\ERPBundle\Form\Type\MonSonataCollectionType
tag:
- { name: form.type, alias: mon_sonata_type_collection }

but i've got an error:
Could not load type "mon_sonata_type_collection"

must i do another thing ?
--
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 http://groups.google.com/group/sonata-users.
For more options, visit https://groups.google.com/d/optout.
et
2014-11-28 16:40:03 UTC
Permalink
$formMapper->add('tous_articles', new LesArticlesType(), array(
'mapped' => false
));



the error is:

Please define a type for field `tous_articles` in
`l3ia\Bundle\ERPBundle\Admin\CommandeAdmin`


but this error doesn't occurs into a classic symfony controller:

$form = $this->createFormBuilder($commande)
->add('ot')
->add('article', new LesArticlesType())
->add('Enregistrer', 'submit')
->getForm();


really, how to use a custom form into sonata ?
--
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 http://groups.google.com/group/sonata-users.
For more options, visit https://groups.google.com/d/optout.
et
2014-12-01 08:07:54 UTC
Permalink
after some new research, i've found a way to insert a custom widget:

$formMapper->add('articles', 'sonata_type_immutable_array',
array(
'label' => 'Les articles :',
'keys' => array(
array('articles', new LesArticlesType(),
array(
'mapped' => false
)
)
)
)
,array(
'admin_code' => 'sonata.admin.CommandeArticle'
)
);
}
Post by et
Hello,
I would like to have a widget like sonata_type_collection, with this
$formMapper->add('articles', 'sonata_type_collection', array(
'required' => true
,'by_reference' => false
,'label' => "AJOUTEZ DES ARTICLES :"
,'disabled' => $commande->estCommandeIssuDeDevis()
,'btn_add' => $commande->estCommandeIssuDeDevis() ? false : 'Ajouter un
article'
),
array(
'edit' => 'inline'
,'multiple' => true
,'expanded' => true
,'inline' => 'table'
,'allow_delete' => ! $commande->estCommandeIssuDeDevis()
,'admin_code' => 'sonata.admin.CommandeArticle'
)
);
protected function configureFormFields(FormMapper $formMapper)
{
$formMapper
->add('Description', null, array(
'attr' => array('style' => 'width: 95%;')
))
->add('Quantite')
->add('article_taille', null, array(
'attr' => array('style' => 'width: 95%;')
))
;
}
<https://lh6.googleusercontent.com/-dM_XRo_usQY/VHg_3I-1ZuI/AAAAAAAAHsE/gJ6-XwIaurQ/s1600/Presse-papiers-2.png>
but i would like to have a line for each element of the select (already
selected)
$formMapper->add('articles', 'mon_sonata_type_collection');
- add the inherited class into l3ia\Bundle\ERPBundle\Form\Type\
namespace l3ia\Bundle\ERPBundle\Form\Type;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormView;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
use Sonata\CoreBundle\Form\EventListener\ResizeFormListener;
class MonSonataCollectionType extends AbstractType
{
/**
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$listener = new ResizeFormListener(
$options['type'],
$options['type_options'],
$options['modifiable'],
$options['pre_bind_data_callback']
);
$builder->addEventSubscriber($listener);
}
/**
*/
public function buildView(FormView $view, FormInterface $form, array
$options)
{
$view->vars['btn_add'] = $options['btn_add'];
$view->vars['btn_catalogue'] = $options['btn_catalogue'];
}
/**
*/
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array(
'modifiable' => false,
'type' => 'text',
'type_options' => array(),
'pre_bind_data_callback' => null,
'btn_add' => 'link_add',
'btn_catalogue' => 'SonataCoreBundle'
));
}
/**
*/
public function getName()
{
return 'mon_sonata_type_collection';
}
}
class: l3ia\Bundle\ERPBundle\Form\Type\MonSonataCollectionType
- { name: form.type, alias: mon_sonata_type_collection }
Could not load type "mon_sonata_type_collection"
must i do another thing ?
--
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 http://groups.google.com/group/sonata-users.
For more options, visit https://groups.google.com/d/optout.
Loading...