Installation Add the bundle via Composer:
composer require canabelle/cms-user-bundle
Register the bundle in config/bundles.php (Symfony):
return [
// ...
Canabelle\CMSUserBundle\CanabelleCMSUserBundle::class => ['all' => true],
];
Publish Assets Run the following to publish migrations, config, and translations:
php bin/console canabelle:cms-user:install
This creates:
database/migrations/...)config/packages/canabelle_cms_user.yaml)Run Migrations
php bin/console doctrine:migrations:migrate
Basic Usage
The bundle provides a User entity (likely extending Symfony’s UserInterface). Check the generated User class in src/Entity/User.php (or app/Entity/User.php if using legacy structure).
Example of fetching a user:
use Canabelle\CMSUserBundle\Entity\User;
$user = $entityManager->getRepository(User::class)->find(1);
Routing & Controllers
The bundle may include basic CRUD routes (check config/routes/canabelle_cms_user.yaml or src/Kernel.php for registration). Override or extend these in your own controllers if needed.
User Management
RegistrationController or creating a custom form type.
// Example: Custom registration form
namespace App\Form;
use Symfony\Component\Form\AbstractType;
use Canabelle\CMSUserBundle\Form\UserType;
class CustomUserType extends UserType {
public function buildForm(FormBuilderInterface $builder, array $options) {
parent::buildForm($builder, $options);
$builder->add('custom_field', TextType::class);
}
}
User entity. Configure firewalls in config/packages/security.yaml:
firewalls:
main:
form_login:
login_path: canabelle_cms_user_login
check_path: canabelle_cms_user_login_check
Role-Based Access
The bundle likely uses Symfony’s role hierarchy. Assign roles in the User entity or via a listener:
$user->setRoles(['ROLE_USER', 'ROLE_CMS_EDITOR']);
$entityManager->persist($user);
Profile Management
Extend the User entity to add custom fields (e.g., avatar, bio):
// src/Entity/User.php
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $avatar;
Update the form type (UserType) to include these fields.
API Integration
If using API Platform or similar, expose the User entity with serialization groups:
use Symfony\Component\Serializer\Annotation\Groups;
class User {
/**
* @Groups({"user:read"})
*/
public $email;
}
Event Listeners
Hook into user lifecycle events (e.g., PrePersist, PostUpdate) via Symfony events:
// src/EventListener/UserListener.php
namespace App\EventListener;
use Canabelle\CMSUserBundle\Entity\User;
use Doctrine\ORM\Event\LifecycleEventArgs;
class UserListener {
public function prePersist(User $user, LifecycleEventArgs $args) {
$user->setCreatedAt(new \DateTime());
}
}
Register the listener in services.yaml:
services:
App\EventListener\UserListener:
tags:
- { name: doctrine.event_listener, event: prePersist }
templates/canabelle_cms_user/ to modify login/registration views.User entity’s validation constraints:
use Symfony\Component\Validator\Constraints as Assert;
class User {
/**
* @Assert\NotBlank
* @Assert\Length(min=8)
*/
private $plainPassword;
}
StoDoctrineExtensionsBundle for soft deletes or timestamps if the bundle doesn’t include them natively.User entity in PHPUnit tests:
$user = $this->createMock(User::class);
$user->method('getRoles')->willReturn(['ROLE_USER']);
Outdated Codebase
make:auth changes in Symfony 5+).lifecycle_callbacks may need adjustment for newer versions).Missing Documentation
Canabelle\CMSUserBundle\Entity\UserCanabelle\CMSUserBundle\Form\UserTypeCanabelle\CMSUserBundle\Controller\RegistrationControllerphp bin/console debug:container Canabelle\CMSUserBundle to list services.Hardcoded Configurations
# config/packages/canabelle_cms_user.yaml
canabelle_cms_user:
templates:
registration: 'custom/path/registration.html.twig'
Security Risks
argon2i). Update the UserPasswordHasher service:
services:
Symfony\Component\Security\Core\Encoder\UserPasswordHasher:
arguments:
- '@security.user_password_hasher.legacy'
Migration Conflicts
User table schema or use doctrine:migrations:diff to generate a custom migration.Enable Debug Mode
Set APP_DEBUG=true in .env to see detailed errors (e.g., missing templates or services).
Check Event Dispatchers
Use debug:event-dispatcher to verify if bundle events (e.g., user.registered) are firing:
php bin/console debug:event-dispatcher
Database Schema Issues Dump the schema to compare with the bundle’s expectations:
php bin/console doctrine:schema:update --dump-sql
Symfony Profiler Use the profiler to inspect:
Custom User Provider Replace the default user provider (e.g., for LDAP or API-based auth):
security:
providers:
custom_user_provider:
id: App\Security\CustomUserProvider
Add Fields Dynamically
Use Doctrine extensions or traits to add fields without modifying the User entity directly:
// src/Entity/UserTrait.php
trait UserTrait {
private $customField;
// Getters/setters...
}
Override Controllers
Extend or replace controllers (e.g., RegistrationController) by defining your own service with the same interface.
Custom Roles
Define roles in security.yaml and assign them via a listener:
security:
role_hierarchy:
ROLE_CMS_ADMIN: [ROLE_USER, ROLE_CMS_EDITOR]
API Tokens
Integrate with lexik/jwt-authentication-bundle for token-based auth:
composer require lexik/jwt-authentication-bundle
Configure in security.yaml to work with the bundle’s User entity.
deprecation-notices in logs for bundle-specific warnings.How can I help you explore Laravel packages today?