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

Block Bundle Laravel Package

symfony-cmf/block-bundle

Symfony CMF BlockBundle lets you create and manage reusable content blocks in Symfony apps, integrating with PHPCR-ODM and the CMF stack. Define blocks in code or the CMS, render them in templates, and reuse them across pages with flexible block types.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation

    composer require symfony-cmf/block-bundle
    

    Ensure sonata-block-bundle is also installed (dependency).

  2. Configuration Add to config/packages/sonata_block.yaml:

    sonata_block:
        default_contexts: [cms]
        blocks:
            sonata.block.service.block: ~
            sonata.block.service.text: ~
            # Add PHPCR-specific blocks if needed
    
  3. First Use Case

    • Create a PHPCR-based block by extending Sonata\BlockBundle\Block\BaseBlockService.
    • Register it in services.yaml:
      App\Block\CustomPhpcrBlock:
          tags: [sonata.block]
      

    Template Path Update (2.1.1+)

    • Replace old template paths (e.g., CmfBlockBundl:Block:some-template.html.twig) with the new Twig namespace format:
      {% extends '@CmfBlock/Block/some-template.html.twig' %}
      

Implementation Patterns

Workflow: PHPCR-Integrated Blocks

  1. Fetching Blocks from PHPCR Use PHPCR\Session to query blocks stored in a PHPCR repository (e.g., Jackalope):

    $session = $this->get('phpcr.session');
    $query = $session->createQuery(
        "SELECT [jcr:path] FROM [nt:base] WHERE [jcr:path] LIKE '/blocks/%'",
        Query::JCR_SQL2
    );
    $results = $query->execute();
    
  2. Dynamic Block Rendering Override execute() in a custom block service:

    public function execute(BlockContextInterface $blockContext, Response $response = null)
    {
        $blockData = $this->getPhpcrBlockData($blockContext->getSetting('path'));
        return $this->renderView('@CmfBlock/Block/custom.html.twig', ['data' => $blockData]);
    }
    
  3. Caching Strategies Cache PHPCR queries and block responses:

    # config/packages/cache.yaml
    app.cache.phpcr_blocks:
        provider: 'file_system'
        namespace: 'phpcr_blocks'
    

Integration Tips

  • Sonata Admin Integration: Extend Sonata\AdminBundle\Admin\Admin to manage PHPCR blocks via the admin panel.
  • Event Listeners: Use sonata.block.event.BLOCK_VIEW to pre-process block data from PHPCR.
  • Twig Extensions: Create a Twig extension to fetch blocks dynamically:
    $this->twig->addExtension(new PhpcrBlockExtension($this->get('phpcr.session')));
    
    Ensure Twig paths use the new namespace format (e.g., @CmfBlock/Block/...).

Gotchas and Tips

Pitfalls

  1. Deprecated PHPCR Support

    • The bundle is archived (last release: 2018). Test compatibility with modern PHPCR (e.g., Jackalope 2.x).
    • Workaround: Fork and update dependencies if needed.
  2. Session Management

    • PHPCR sessions are not thread-safe. Avoid sharing sessions across requests.
    • Fix: Use a request-scoped service:
      services:
          app.phpcr.session:
              factory: ['@phpcr.session_factory', 'get']
              arguments: ['default']
              public: false
      
  3. Query Performance

    • Deep queries (e.g., /blocks/**) can be slow. Use jcr:like sparingly.
    • Tip: Index frequently queried paths in PHPCR.
  4. Template Path Breaking Change (2.1.1)

    • Old: CmfBlockBundl:Block:some-template.html.twig (deprecated).
    • New: @CmfBlock/Block/some-template.html.twig.
    • Impact: Update all Twig templates and block services to use the new namespace format.
    • Fix: Run a global search-replace in your project for the old template paths.

Debugging

  • Enable PHPCR Logging:
    # config/packages/monolog.yaml
    handlers:
        phpcr:
            type: stream
            path: "%kernel.logs_dir%/phpcr.log"
            level: debug
    
  • Validate Block Paths: Ensure paths in blockContext->getSetting('path') exist in PHPCR.
  • Template Errors: Verify Twig templates now use the @CmfBlock/Block/ namespace.

Extension Points

  1. Custom Block Types Extend Sonata\BlockBundle\Block\BlockContextInterface to add PHPCR-specific settings:

    class PhpcrBlockContext extends BlockContext
    {
        public function getPhpcrNode(): NodeInterface
        {
            return $this->session->getNode($this->getSetting('phpcr_path'));
        }
    }
    
  2. Repository Abstraction Decouple PHPCR logic with a service:

    class PhpcrBlockRepository
    {
        public function findBlock(string $path): ?NodeInterface
        {
            // Custom logic to fetch from PHPCR
        }
    }
    
  3. Migration Path If moving away from PHPCR, use Doctrine Migrations to export block data to a relational DB.

    • Note: Ensure template paths are updated to the new format before migration.
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.
emuniq/filament-browser-notifications
syriable/filament-translator
hungnm28/livewire-form
wenprise/eloquent
crudly/encrypted
fadion/bouncy
cuci/prototurk-sdk
gos/pubsub-router-bundle
cuci/prototurk-sdk-symfony
clementtalleu/easyadmin-markdown-bundle
codeflextech/permission-manager
karnoweb/livewire-datepicker
sayedenam/sayed-dashboard
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui