Closed charafsalmi closed 5 years ago
I forgot to add :
<?php
namespace AppBundle\Form\Type;
use FOS\MessageBundle\Util\LegacyFormHelper;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\AbstractType;
use \AppBundle\Form\Type\RecipientsType;
/**
* Message form type for starting a new conversation with multiple recipients.
*
* @author Łukasz Pospiech <zocimek@gmail.com>
*/
class NewThreadMultipleMessageFormType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('recipients', RecipientsType::class, array(
'label' => 'recipients',
'translation_domain' => 'FOSMessageBundle',
))
->add('subject', LegacyFormHelper::getType('Symfony\Component\Form\Extension\Core\Type\TextType'), array(
'label' => 'subject',
'translation_domain' => 'FOSMessageBundle',
))
->add('body', LegacyFormHelper::getType('Symfony\Component\Form\Extension\Core\Type\TextareaType'), array(
'label' => 'body',
'translation_domain' => 'FOSMessageBundle',
));
}
/**
* {@inheritdoc}
*/
public function getBlockPrefix()
{
return 'fos_message_new_multiperson_thread';
}
/**
* @deprecated To remove when supporting only Symfony 3
*/
public function getName()
{
return $this->getBlockPrefix();
}
}
<?php
namespace AppBundle\Form\Type;
use FOS\MessageBundle\Util\LegacyFormHelper;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
use AppBundle\DataTransformer\RecipientsDataTransformer;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
/**
* Description of RecipientsType.
*
* @author Łukasz Pospiech <zocimek@gmail.com>
*/
class RecipientsType extends AbstractType
{
/**
* @var RecipientsDataTransformer
*/
private $recipientsTransformer;
/**
* @param RecipientsDataTransformer $transformer
*/
public function __construct(RecipientsDataTransformer $transformer)
{
$this->recipientsTransformer = $transformer;
}
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->addModelTransformer($this->recipientsTransformer);
}
/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'invalid_message' => 'no user !',
));
}
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$this->configureOptions($resolver);
}
/**
* {@inheritdoc}
*/
public function getBlockPrefix()
{
return 'recipients_selector';
}
/**
* {@inheritdoc}
*/
public function getParent()
{
return ChoiceType::class;
}
/**
* @deprecated To remove when supporting only Symfony 3
*/
public function getName()
{
return $this->getBlockPrefix();
}
}
with the way the bundle is constructed, you'd need to create some custom logic for this
however, as this issue is over two years old and I'm tidying up this bundle, if it's still relevant please re-open the issue
I am struggling trying to use a Select Input Field to display a Select2 widget instead of the Text Input Field.
I add new services in
services.yml
:And config.xml
Then, I dupplicated these services' files in the right places.
I also created a JSON Controller to give back the filtered list of users ID I want my Select2 to display.
But when I try to send a message to the right user, it says that this user doesn't exist.
I can not figure out how the data transformers handle the information in this case.
The
RecipientsDataTransformer->transform
method allows get an empty array as a parameter. How is that possible when the select input field returns an ID ?What can I do more ?
Thank you.