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

Content Bundle Laravel Package

symfony-cmf/content-bundle

Symfony CMF Content Bundle for integrating a content repository (PHPCR/Doctrine) into Symfony apps. Provides document mapping, content models, persistence and admin-friendly tools to build CMS features on top of CMF components.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup in Laravel

Since symfony-cmf/content-bundle is Symfony-based, integration into Laravel requires Symfony Bridge or Laravel Symfony Components. Start by:

  1. Install via Composer (if using Symfony Bridge):

    composer require symfony-cmf/content-bundle
    

    For Laravel-only projects, use symfony/cmf-bundle as a reference and manually port core concepts (e.g., Document, RouteProviderInterface).

  2. Configure Routing: The bundle relies on Symfony’s Routing component. In Laravel, mimic this with:

    // routes/web.php
    Route::get('/content/{slug}', [ContentController::class, 'show']);
    
  3. Define a Basic Document Model: Extend Symfony\CMF\Component\Routing\RouteObjectInterface:

    namespace App\Models;
    
    use Symfony\CMF\Component\Routing\RouteObjectInterface;
    
    class Page implements RouteObjectInterface
    {
        public function getRoute(): array
        {
            return [
                '_controller' => 'App\Http\Controllers\PageController::show',
                'slug' => $this->slug,
            ];
        }
    }
    
  4. First Use Case: Create a PageController to render content:

    namespace App\Http\Controllers;
    
    use App\Models\Page;
    use Illuminate\Http\Request;
    
    class PageController extends Controller
    {
        public function show(Request $request, Page $page)
        {
            return view('pages.show', ['page' => $page]);
        }
    }
    

Implementation Patterns

1. Content Modeling

  • Hierarchical Content: Use Symfony\CMF\Component\Routing\RouteObjectInterface for nested routes (e.g., blogs with categories).

    class BlogPost extends Page
    {
        public function getRoute(): array
        {
            return [
                '_controller' => 'App\Http\Controllers\BlogPostController::show',
                'slug' => $this->slug,
                'category' => $this->category->slug, // Nested route
            ];
        }
    }
    
  • Dynamic Routes: Leverage RouteProviderInterface to generate routes dynamically:

    namespace App\Providers;
    
    use Symfony\CMF\Component\Routing\RouteProviderInterface;
    
    class AppRouteProvider implements RouteProviderInterface
    {
        public function getRouteCollection()
        {
            $collection = new RouteCollection();
            $collection->add('home', $this->createHomeRoute());
            return $collection;
        }
    }
    

2. Integration with Laravel Ecosystem

  • Eloquent + CMF: Combine with Laravel’s Eloquent for persistence:

    use Illuminate\Database\Eloquent\Model;
    use Symfony\CMF\Component\Routing\RouteObjectInterface;
    
    class EloquentPage extends Model implements RouteObjectInterface
    {
        protected $fillable = ['title', 'slug', 'content'];
        // ...
    }
    
  • Blade Templates: Use Blade to render CMF-powered content:

    @foreach($pages as $page)
        <a href="{{ route('content.show', $page->slug) }}">
            {{ $page->title }}
        </a>
    @endforeach
    

3. Workflow: Content Creation

  1. Admin Panel: Build a Laravel Nova/Backpack form to create Page models with slug and content.
  2. Route Generation: Use a RouteServiceProvider to load CMF routes:
    public function boot()
    {
        parent::boot();
        $this->router->getRouteCollection()->addCollection(
            app(AppRouteProvider::class)->getRouteCollection()
        );
    }
    

Gotchas and Tips

Pitfalls

  1. Archived Package:

    • No active maintenance; expect compatibility issues with newer Symfony/Laravel versions.
    • Workaround: Fork and update dependencies (e.g., symfony/routing).
  2. Route Overrides:

    • CMF routes may conflict with Laravel’s default routing. Use middleware to prioritize:
      Route::middleware(['cmf.routes'])->group(function () {
          // CMF routes here
      });
      
  3. Database Migrations:

    • CMF assumes Symfony’s Doctrine ORM. For Laravel, manually map RouteObjectInterface to Eloquent:
      // Migration for pages table
      Schema::create('pages', function (Blueprint $table) {
          $table->id();
          $table->string('slug')->unique();
          $table->text('content');
          $table->timestamps();
      });
      

Debugging

  • Route Dumping: Use Symfony’s RouteDebuggerBundle (if bridged) or dump Laravel routes:

    php artisan route:list
    

    Filter for CMF-generated routes (e.g., prefixed with content).

  • Route Matching Issues: Ensure RouteObjectInterface::getRoute() returns a valid Laravel route array:

    // Bad: Symfony-specific controller format
    return ['_controller' => 'AppBundle:Page:show'];
    
    // Good: Laravel-compatible
    return ['uses' => 'App\Http\Controllers\PageController@show'];
    

Extension Points

  1. Custom Route Loaders: Extend RouteProviderInterface to add logic (e.g., cache routes):

    class CachedRouteProvider implements RouteProviderInterface
    {
        public function getRouteCollection()
        {
            return Cache::remember('cmf.routes', now()->addHours(1), function () {
                return parent::getRouteCollection();
            });
        }
    }
    
  2. Content Events: Dispatch Laravel events for CMF actions (e.g., PageCreated):

    event(new PageCreated($page));
    

    Listen in EventServiceProvider:

    protected $listen = [
        PageCreated::class => [
            UpdateSearchIndex::class,
        ],
    ];
    
  3. API Integration: Use Laravel’s API resources to expose CMF content:

    namespace App\Http\Resources;
    
    use App\Models\Page;
    use Illuminate\Http\Resources\Json\JsonResource;
    
    class PageResource extends JsonResource
    {
        public function toArray($request)
        {
            return [
                'slug' => $this->slug,
                'content' => $this->content,
                'route' => route('content.show', $this->slug),
            ];
        }
    }
    
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.
terminal42/code-quality-tools
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky