Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Doctrine Phpcr Admin Bundle Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Steps to First Use

  1. Install Dependencies:

    composer require sonata-project/doctrine-phpcr-admin-bundle
    composer require doctrine/phpcr-odm-bundle
    composer require symfony/orm-pack
    
  2. 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"
    
  3. Enable Bundles (config/bundles.php):

    return [
        // ...
        SonataDoctrinePhpcrAdminBundle\SonataDoctrinePhpcrAdminBundle::class => ['all' => true],
        SonataAdminBundle\SonataAdminBundle::class => ['all' => true],
    ];
    
  4. 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;
    }
    
  5. 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';
    }
    
  6. Configure Routing (config/routes.yaml):

    sonata_admin:
        resource: "@SonataDoctrinePhpcrAdminBundle/Resources/config/routing/tree.xml"
        prefix: /admin
    
  7. Clear Cache and Test:

    php bin/console cache:clear
    php bin/console doctrine:phpcr:install
    

First Use Case: Creating a Nested Page Structure

  • Navigate to /admin/page in your browser.
  • Use the "Tree" view to drag-and-drop pages into hierarchical relationships.
  • Edit pages via the "List" or "Create" views.

Implementation Patterns

Core Workflows

1. Hierarchical CRUD Operations

  • Tree View: Built-in drag-and-drop interface for parent-child relationships.
    {% 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 %}
    
  • Form Integration: Automatically handles ReferenceOne/ReferenceMany fields for parent-child links.
    $builder->add('parent', 'doctrine_phpcr_odm_tree', [
        'class' => 'App\Document\Page',
        'property' => 'parent',
    ]);
    

2. Customizing Tree Behavior

  • Override Tree Templates: Extend SonataDoctrinePHPCRAdminBundle:Block:tree.html.twig to modify UI.
    {% extends 'SonataDoctrinePHPCRAdminBundle:Block:tree.html.twig' %}
    {% block tree_node_label %}
        {{ node.title }} (ID: {{ node.id }})
    {% endblock %}
    
  • Configure Tree Options (config/packages/sonata_doctrine_phpcr.yaml):
    sonata_doctrine_phpcr_admin:
        document_tree_options:
            confirm_move: true
            depth: 5
            precise_children: true
    

3. Permissions and ACLs

  • Enable Sonata’s ACL editor for PHPCR documents:
    sonata_admin:
        security:
            handler: sonata.admin.security.handler.acl
    
  • Restrict tree access by role:
    protected function configurePermissions()
    {
        return ['VIEW', 'EDIT', 'DELETE', 'CREATE', 'MOVE'];
    }
    

4. Bulk Operations

  • Use SonataAdmin’s built-in batch actions (e.g., delete, publish) via the "List" view.
  • Example: Add a custom batch action in configureBatchActions():
    protected function configureBatchActions()
    {
        $this->addBatchAction('publish', 'Publish', 'fa-paper-plane');
    }
    

5. Integration with Custom Services

  • Access the PHPCR repository in a service:
    use Doctrine\ODM\PHPCR\DocumentManager;
    
    class MyService {
        public function __construct(private DocumentManager $dm) {}
    
        public function getRootNode() {
            return $this->dm->find(null, '/cmf');
        }
    }
    

Laravel-Specific Adaptations

Since this bundle is Symfony-focused, Laravel developers would need to:

  1. Use Symfony Components: Leverage symfony/console, symfony/dependency-injection, and symfony/http-kernel via Composer.
  2. Mock the Kernel: Override Symfony’s Kernel in Laravel’s service container:
    $kernel = new SymfonyKernel($app->make('config'), true);
    $kernel->boot();
    
  3. Route Integration: Use Laravel’s routing to proxy requests to Symfony’s admin routes:
    Route::get('/admin/{path}', function ($path) {
        return $kernel->handle(
            Request::create("/admin/{$path}", 'GET')
        );
    });
    
  4. Asset Management: Publish Symfony assets to Laravel’s public folder:
    php bin/console assets:install public
    

Gotchas and Tips

Pitfalls

  1. Abandoned Package Risks:

    • Symfony 5/6+ Compatibility: The last release (2019) lacks PHP 8 or Symfony 5+ support. Test thoroughly or fork.
    • Dependency Conflicts: May clash with newer versions of sonata-project/core-bundle or doctrine/phpcr-odm. Use composer why-not to debug.
    • Template Changes: Twig template paths were renamed in v2.1.1 (e.g., SonataDoctrinePHPCRAdminBundle:CRUD:edit_orm_one_to_oneSonataDoctrinePHPCRAdminBundle:CRUD:edit_phpcr_one_to_one).
  2. PHPCR-Specific Issues:

    • Node Path Limits: PHPCR has a default path length limit (~2000 characters). Avoid deeply nested structures.
    • Transaction Handling: PHPCR-ODM uses nested transactions. Long-running operations may hit limits.
    • Case Sensitivity: Node paths are case-sensitive on some backends (e.g., Jackrabbit).
  3. Configuration Quirks:

    • Missing root_node: Forgetting to set root_node in doctrine_phpcr.yaml causes NodeNotFoundException.
    • ACL Misconfiguration: If ACLs are enabled but not properly configured, tree operations may fail with AccessDeniedException.
    • Routing Conflicts: Ensure sonata_admin routes are loaded after your custom routes to avoid overlaps.
  4. Performance:

    • Large Trees: Loading deep trees (>1000 nodes) may cause timeouts. Use depth in document_tree_options to limit traversal.
    • Lazy Loading: PHPCR-ODM lazy-loads nodes. Eager-load related nodes in queries to avoid N+1 issues:
      $query->leftJoin('node.children')->where(...);
      

Debugging Tips

  1. Enable PHPCR Logging:

    doctrine:
        orm:
            logging: true
            logging_level: DEBUG
    

    Check logs for PHPCR entries during operations.

  2. Dump Node Structures:

    use Doctrine\ODM\PHPCR\DocumentManager;
    
    $node = $dm->find(null, '/cmf');
    var_dump($node->getPath(), $node->getChildren());
    
  3. 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
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
nasirkhan/laravel-sharekit
directorytree/privacy-filter-classifier
directorytree/privacy-filter
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
22h/doctrine-garbage-collection-bundle
agtp/agtp-php
agtp/mod-php
splash/sonata-admin
splash/metadata
splash/openapi
splash/scopes
splash/toolkit
testo/output-teamcity
testo/bridge-symfony