symfony-cmf/core-bundle
Symfony CMF Core Bundle provides shared infrastructure for CMF bundles: base classes, helpers, configuration and integration glue for Symfony projects. Supports content repositories (e.g., PHPCR), routing, and common services to build content-managed sites.
Installation
composer require symfony-cmf/core-bundle
Add to config/bundles.php:
return [
// ...
SymfonyCmf\Bundle\CoreBundle\SymfonyCmfCoreBundle::class => ['all' => true],
];
First Use Case: Rendering a Content Document
Inject the ContentResolverInterface and ContentFactoryInterface into a controller or service:
use SymfonyCmf\Bundle\CoreBundle\Resolver\ContentResolverInterface;
use SymfonyCmf\Bundle\CoreBundle\Factory\ContentFactoryInterface;
public function __construct(
private ContentResolverInterface $contentResolver,
private ContentFactoryInterface $contentFactory
) {}
public function showDocument(Document $document)
{
$resolvedContent = $this->contentResolver->resolve($document);
return $this->render('document/show.html.twig', [
'content' => $resolvedContent,
]);
}
Key Classes to Explore
ContentResolverInterface: Resolves documents to renderable content.ContentFactoryInterface: Creates new content instances.Content and Document entities (check src/Entity/ in the bundle).Resolve Content
Use ContentResolver to fetch and resolve a document:
$content = $this->contentResolver->resolve($document);
cmf_core.yaml).Modify Content (Pre-Render) Extend or wrap the resolver to add logic:
$content->setProperty('custom_field', $value); // If using Doctrine extensions
Render with Twig Access properties via Twig:
{{ content.title }}
{{ content.body|raw }}
SymfonyCmf\Bundle\CoreBundle\Doctrine\Phpcr\DocumentManager for PHPCR (if installed).Content and map to your entities:
# config/doctrine/orm/Entity/YourContent.orm.yml
SymfonyCmf\Bundle\CoreBundle\Model\Content:
inheritanceType: JOINED
table: your_content
fields:
title: ~
Listen to cmf.content.pre_resolve or cmf.content.post_resolve events:
// src/EventListener/CustomContentListener.php
public function onPreResolve(ContentEvent $event)
{
$content = $event->getContent();
if ($content->getType() === 'page') {
$content->setProperty('meta_tags', $this->generateMetaTags());
}
}
PHPCR vs. Doctrine ORM
symfony-cmf/doctrine-orm-bundle and configure cmf_core.yaml:
cmf_core:
document_manager: doctrine_orm
Caching Quirks
php bin/console cache:clear
Content Type Mismatches
Content entity extends SymfonyCmf\Bundle\CoreBundle\Model\Content and is mapped correctly. Use:
php bin/console debug:cmf:content-types
dump($this->contentResolver->resolve($document));
cmf_core.yaml under resolver.chain.Custom Resolvers
Implement ResolverInterface and register in services.yaml:
services:
App\Resolver\CustomResolver:
tags:
- { name: 'cmf.resolver', priority: 10 }
Override Content Factory
Extend ContentFactory and bind it in DI:
// src/Factory/CustomContentFactory.php
class CustomContentFactory extends ContentFactory {}
services:
SymfonyCmf\Bundle\CoreBundle\Factory\ContentFactory:
alias: App\Factory\CustomContentFactory
Twig Extensions
Add custom filters/filters to resources/config/twig.yaml:
twig:
globals:
cmf_content_helper: '@SymfonyCmf\Bundle\CoreBundle\Twig\ContentExtension'
How can I help you explore Laravel packages today?