FDPrivateMessageBundle
, (*1)
This bundle provides a conversation system to your users., (*2)
, (*3)
Requirements
- Symfony >= 2.8
- A user class implementing
Symfony\Component\Security\Core\User\UserInterface
Translations
If you wish to use default texts provided in this bundle, you have to make sure you have translator enabled in your config., (*4)
# app/config/config.yml
framework:
translator: ~
Installation
Step 1: Download FDPrivateMessageBundle using composer
Require the bundle with composer:, (*5)
composer require firediy/private-message-bundle dev-master
Step 2: Enable the bundle
Enable the bundle in the kernel:, (*6)
<?php
// app/AppKernel.php
public function registerBundles()
{
$bundles = array(
// ...
new FD\PrivateMessageBundle\FDPrivateMessageBundle(),
// ...
);
}
Step 3: Create your own User class
The goal of this bundle is to provide a private message system to allow users communicating between them.
FDPrivateMessageBundle does not provide a ready-to-use User entity but uses Symfony's UserInterface., (*7)
So, you just have to create your own User class implementing Symfony\Component\Security\Core\User\UserInterface
.
You can even use FOSUserBundle., (*8)
Now you have your User entity, you just have to tell FDPrivateMessageBundle to use it :, (*9)
# app/config/config.yml
doctrine:
orm:
resolve_target_entities:
Symfony\Component\Security\Core\User\UserInterface: AcmeBundle\Entity\YourUserEntiy
Step 5: Import FDPrivateMessageBundle routing files
Now that you have activated and configured the bundle, all that is left to do is import the FDPrivateMessageBundle routing files., (*10)
# app/config/routing.yml
fd_private_message:
resource: "@FDPrivateMessageBundle/Resources/config/routing.yml"
Step 6: Update your database schema
Finally, just update your database schema :, (*11)
php bin/console doctrine:schema:update --force
You are able to override FDPrivateMessageBundle's forms., (*12)
In example, you're using FOSUserBundle and want to load only recipients being NOT locked :, (*13)
use Doctrine\ORM\EntityRepository;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\FormBuilderInterface;
use FD\PrivateMessageBundle\Form\ConversationType as BaseType;
// Make your form extends FDPrivateMessageBunde::ConversationType.
class ConversationType extends BaseType
{
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
// Call parent's builder.
parent::buildForm($builder, $options);
// Load only users being enabled.
$builder->add('recipients', EntityType::class, array(
'class' => 'AcmeBundle:YourUserEntity',
'multiple' => true,
'query_builder' => function(EntityRepository $er) {
return $er->createQueryBuilder('u')
->where('u.locked', false);
},
));
}
}
Override default FDPrivateMessageBundle templates
Example: Override the conversation's show.html.twig template
Just create a new file in app/Resources/FDPrivateMessageBundle/views/Conversation/show.html.twig
, (*14)
Overridden template
{{ conversation.subject }}