This file is a deterministic, copy-pasteable integration guide for AI coding agents adding ContentBlocks to an existing Symfony application. Humans should read the documentation site; this file is the condensed, unambiguous version.
Scope: you are integrating the published packages into a host app. If you are working inside this monorepo, see
CLAUDE.mdinstead.
- PHP >= 8.2 (>= 8.4 for Symfony 8.0), with
pdo_mysqlif using MySQL - Symfony 6.4 LTS, 7.x, or 8.x
- Doctrine ORM ^2.12 or ^3.0
- Node.js >= 18 with AssetMapper or Webpack Encore configured
- The host app has an entity with a public URL (e.g.
Page,Product)
composer require klehm/content-blocks klehm/content-blocks-kit// config/bundles.php
ContentBlocks\ContentBlocksBundle::class => ['all' => true],
ContentBlocks\Kit\ContentBlocksKitBundle::class => ['all' => true],# config/routes/content_blocks.yaml
content_blocks:
resource: '@ContentBlocksBundle/config/routes.php'The host's Stimulus Bundle does not auto-discover third-party controllers. Add to
assets/controllers.json:
{
"controllers": {
"@klehm/content-blocks": {
"cb-builder-launcher": { "enabled": true, "fetch": "eager", "autoimport": { "@klehm/content-blocks/styles/admin.css": true } },
"cb-builder": { "enabled": true, "fetch": "eager" },
"cb-autosave": { "enabled": true, "fetch": "eager" },
"cb-section-settings-form": { "enabled": true, "fetch": "eager" },
"cb-spacing-link": { "enabled": true, "fetch": "eager" },
"cb-viewport-tabs": { "enabled": true, "fetch": "eager" },
"cb-collection-sort": { "enabled": true, "fetch": "eager" },
"cb-condition": { "enabled": true, "fetch": "eager" },
"cb-file-upload": { "enabled": true, "fetch": "eager" }
},
"@klehm/content-blocks-kit": {
"cb-tinymce": { "enabled": true, "fetch": "eager" },
"cb-gallery": { "enabled": true, "fetch": "eager" }
}
},
"entrypoints": []
}Then:
php bin/console importmap:require sortablejs # cb-collection-sort dependency
php bin/console asset-map:compilecascade: ['persist', 'remove'] is REQUIRED (the form returns a transient area).
use ContentBlocks\Entity\ContentArea;
#[ORM\OneToOne(targetEntity: ContentArea::class, cascade: ['persist', 'remove'])]
#[ORM\JoinColumn(nullable: true, onDelete: 'SET NULL')]
private ?ContentArea $contentArea = null;php bin/console doctrine:migrations:diff
php bin/console doctrine:migrations:migrateDefaults deny all access / throw. You MUST provide both.
# config/services.yaml
services:
ContentBlocks\Security\AccessCheckerInterface:
class: App\Security\PageAccessChecker
ContentBlocks\Preview\ContentAreaUrlResolverInterface:
class: App\Preview\PageContentAreaUrlResolverAccessCheckerInterface::canEdit(ContentArea): bool— authorize mutations (own the parent entity?).ContentAreaUrlResolverInterface::resolve(ContentArea): string— return the public URL of the area's owner (used for the iframe preview).
Implementations: https://klehm.github.io/content-blocks-project/guide/host-services
use ContentBlocks\Form\Type\ContentAreaType;
$builder->add('contentArea', ContentAreaType::class);{# public template — REQUIRED: this call produces the editable markers #}
{{ cb_render_content_area(page.contentArea) }}
{# in your <head>, for kit block styles #}
<link rel="stylesheet" href="{{ path('content_blocks_kit_asset_css') }}"># config/packages/framework.yaml — CSRF tokens are session-bound
framework:
session: true
csrf_protection: { enabled: true }# config/packages/security.yaml — single-firewall example
security:
access_control:
- { path: ^/_content-blocks/public, roles: PUBLIC_ACCESS }
- { path: ^/_content-blocks, roles: ROLE_ADMIN }Separate admin/front firewalls: see https://klehm.github.io/content-blocks-project/guide/security
-
composer requiresucceeded; both bundles inconfig/bundles.php
<
3DA7
li class="task-list-item"> - Migration created
cb_content_area,cb_section,cb_column,cb_block - Both required services are aliased in
services.yaml - Public template calls
cb_render_content_area() - Kit stylesheet
<link>is in the front layout - As an authenticated editor, "Edit content" opens the builder and the preview shows the real page
assets/controllers.json has both controller packages; asset-map:compile runs clean
Restrict/tune the 19 blocks under content_blocks_kit.blocks.<type> (enabled,
options, choices, defaults). Inspect any block's surface:
bin/console content-blocks-kit:blocks --format=jsonReference: https://klehm.github.io/content-blocks-project/kit/configuration
One class + one Symfony form, tagged #[AsContentBlock], auto-registers. The form
IS the data whitelist/validator. See
https://klehm.github.io/content-blocks-project/guide/custom-blocks