sonata-project/doctrine-phpcr-admin-bundle
Integrates Doctrine PHPCR with SonataAdminBundle for Symfony, enabling admin interfaces for PHPCR documents. Includes docs and CI badges, but note: this repository is abandoned with no active support; contributions welcome.
Install Dependencies:
composer require sonata-project/doctrine-phpcr-admin-bundle
composer require doctrine/phpcr-odm-bundle
composer require symfony/orm-pack
Configure PHPCR-ODM (config/packages/doctrine_phpcr.yaml):
doctrine_phpcr:
document_managers:
default:
connection: default
backend:
type: "doctrinephpcr:filesystem"
directory: "%kernel.project_dir%/var/phpcr"
root_node: "/cmf"
Enable Bundles (config/bundles.php):
return [
// ...
SonataDoctrinePhpcrAdminBundle\SonataDoctrinePhpcrAdminBundle::class => ['all' => true],
SonataAdminBundle\SonataAdminBundle::class => ['all' => true],
];
Create a PHPCR Document Class (src/Document/Page.php):
namespace App\Document;
use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCR;
use Sonata\DoctrinePHPCRAdminBundle\Admin\AbstractDocumentAdmin;
/**
* @PHPCR\Document(repositoryClass="App\Document\PageRepository")
*/
class Page
{
/**
* @PHPCR\String(id=true)
*/
public $id;
/**
* @PHPCR\String
*/
public $title;
/**
* @PHPCR\ReferenceOne(targetDocument="App\Document\Page")
*/
public $parent;
}
Register Admin Class (src/Admin/PageAdmin.php):
namespace App\Admin;
use Sonata\DoctrinePHPCRAdminBundle\Admin\AbstractDocumentAdmin;
class PageAdmin extends AbstractDocumentAdmin
{
protected $documentClass = 'App\Document\Page';
protected $baseRouteName = 'page';
protected $baseRoutePattern = 'page';
}
Configure Routing (config/routes.yaml):
sonata_admin:
resource: "@SonataDoctrinePhpcrAdminBundle/Resources/config/routing/tree.xml"
prefix: /admin
Clear Cache and Test:
php bin/console cache:clear
php bin/console doctrine:phpcr:install
/admin/page in your browser.{% block sonata_block %}
{{ sonata_block_service('sonata.doctrine.phpcr.admin.tree', {
'repository_name': 'default',
'root_node': '/cmf',
'routing_defaults': {'controller': 'page_admin', 'action': 'list'}
}) }}
{% endblock %}
ReferenceOne/ReferenceMany fields for parent-child links.
$builder->add('parent', 'doctrine_phpcr_odm_tree', [
'class' => 'App\Document\Page',
'property' => 'parent',
]);
SonataDoctrinePHPCRAdminBundle:Block:tree.html.twig to modify UI.
{% extends 'SonataDoctrinePHPCRAdminBundle:Block:tree.html.twig' %}
{% block tree_node_label %}
{{ node.title }} (ID: {{ node.id }})
{% endblock %}
config/packages/sonata_doctrine_phpcr.yaml):
sonata_doctrine_phpcr_admin:
document_tree_options:
confirm_move: true
depth: 5
precise_children: true
sonata_admin:
security:
handler: sonata.admin.security.handler.acl
protected function configurePermissions()
{
return ['VIEW', 'EDIT', 'DELETE', 'CREATE', 'MOVE'];
}
configureBatchActions():
protected function configureBatchActions()
{
$this->addBatchAction('publish', 'Publish', 'fa-paper-plane');
}
use Doctrine\ODM\PHPCR\DocumentManager;
class MyService {
public function __construct(private DocumentManager $dm) {}
public function getRootNode() {
return $this->dm->find(null, '/cmf');
}
}
Since this bundle is Symfony-focused, Laravel developers would need to:
symfony/console, symfony/dependency-injection, and symfony/http-kernel via Composer.Kernel in Laravel’s service container:
$kernel = new SymfonyKernel($app->make('config'), true);
$kernel->boot();
Route::get('/admin/{path}', function ($path) {
return $kernel->handle(
Request::create("/admin/{$path}", 'GET')
);
});
public folder:
php bin/console assets:install public
Abandoned Package Risks:
sonata-project/core-bundle or doctrine/phpcr-odm. Use composer why-not to debug.SonataDoctrinePHPCRAdminBundle:CRUD:edit_orm_one_to_one → SonataDoctrinePHPCRAdminBundle:CRUD:edit_phpcr_one_to_one).PHPCR-Specific Issues:
Configuration Quirks:
root_node: Forgetting to set root_node in doctrine_phpcr.yaml causes NodeNotFoundException.AccessDeniedException.sonata_admin routes are loaded after your custom routes to avoid overlaps.Performance:
depth in document_tree_options to limit traversal.$query->leftJoin('node.children')->where(...);
Enable PHPCR Logging:
doctrine:
orm:
logging: true
logging_level: DEBUG
Check logs for PHPCR entries during operations.
Dump Node Structures:
use Doctrine\ODM\PHPCR\DocumentManager;
$node = $dm->find(null, '/cmf');
var_dump($node->getPath(), $node->getChildren());
Common Errors and Fixes:
| Error | Solution |
|---|---|
Child "_delete" does not exist |
Ensure DELETE permission is granted in ACLs. |
NodeNotFoundException |
Verify root_node in doctrine_phpcr.yaml matches your backend. |
| `Class "Sonata\Form\Type\Tree |
How can I help you explore Laravel packages today?