alterphp/easyadmin-mongo-odm-bundle
Install the Bundle
composer require alterphp/easyadmin-mongo-odm-bundle:dev-master
Ensure easycorp/easyadmin-bundle (v2.0+) is already installed.
Configure the Bundle
Add the bundle to config/bundles.php:
return [
// ...
AlterPhp\EasyAdminMongoOdmBundle\EasyAdminMongoOdmBundle::class => ['all' => true],
];
Register Documents
Define your MongoDB documents in config/packages/easy_admin_mongo_odm.yaml:
easy_admin_mongo_odm:
documents:
App\Document\User:
class: App\Document\User
list:
fields: ['name', 'email']
Route to Admin Panel
Extend easy_admin.yaml to include menu items:
easy_admin:
design:
menu:
- { label: 'Users', route: easyadmin_mongo_odm, params: { document: App\Document\User } }
First Use Case
Access /admin (or your custom route) to see the CRUD interface for User documents.
Note: Actions like new, edit, and delete are restricted (see Gotchas).
list or form sections under each document.
App\Document\Product:
class: App\Document\Product
list:
fields: ['name', 'price', 'createdAt']
sort: ['name', 'asc']
format (if PropertyConfigPass is implemented in future versions).
fields:
- { field: price, format: 'currency' } # Placeholder for future support
App\Document\Order:
list:
filters: ['status', 'date']
search: ['customerName']
templates/document/crud.html.twig) to add buttons or logic.
Example: Add a "Ship" button for Order documents.list.fields.form.fields (if configured) populate the edit view.
form:
fields: ['name', 'description', 'tags']
__SORT_ONLY_INDEXES__). Override in config:
list:
sort: ['nonIndexedField', 'asc'] # May impact performance
vendor/alterphp/easyadmin-mongo-odm-bundle/resources/templates/ to templates/EasyAdminMongoOdmBundle/ in your project.
Example: Customize crud.html.twig for document-specific layouts.@ReferenceOne, @ReferenceMany) are not implemented (__NO_ASSOCIATION__).
Workaround: Use embedded documents or manual field rendering for now.Restricted Actions
new, edit, and delete are disabled by default (__RESTRICTED_ACTIONS__).Sorting Limitations
__SORT_ONLY_INDEXES__).createdAt) are indexed in MongoDB.Missing Features
// Example: Custom repository method
public function findByStatus(string $status) {
return $this->createQueryBuilder()->field('status')->equals($status)->getQuery()->execute();
}
format for Fields: Field formatting (e.g., dates, currencies) is not yet supported (PropertyConfigPass TODOs).Template Overrides
EasyAdminBundle first. Ensure your overrides are in the correct namespace:
templates/EasyAdminMongoOdmBundle/document/crud.html.twig
Menu Items
php bin/console debug:router | grep easyadmin_mongo_odm
config/packages/doctrine_mongodb.yaml:
doctrine_mongodb:
connections:
default:
logging: true
php bin/console cache:clear
Custom Actions
Extend the bundle by creating a custom controller or event subscriber to handle actions like new or delete.
Example:
// src/EventListener/MongoOdmActionsListener.php
public function onKernelRequest(GetResponseEvent $event) {
if ($event->isMasterRequest() && str_starts_with($event->getRequest()->getPathInfo(), '/admin')) {
// Add logic for restricted actions
}
}
QueryBuilder Support
Contribute to the bundle by implementing QueryBuilder integration (see TODOs). Focus on:
@ReferenceOne/@ReferenceMany.Field Formatting
Implement PropertyConfigPass to support field-specific formatting (e.g., dates, enums). Look at EasyAdmin’s PropertyConfigPass for reference.
Association Support
Add support for @ReferenceOne/@ReferenceMany by extending the bundle’s DocumentMapper or CrudController.
App\Document\User, not app/document/user).symfony/uid (for ID handling), but ensure your documents use Uuid or ObjectId appropriately.
How can I help you explore Laravel packages today?