Installation:
composer require edsi-tech/sir-trevor-bundle
Register the bundle in app/AppKernel.php:
new EdsiTech\SirTrevorBundle\EdsiTechSirTrevorBundle(),
Define a Block Entity:
Extend AbstractBlock and map it to Doctrine:
use EdsiTech\SirTrevorBundle\Entity\AbstractBlock;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
* @ORM\Table(name="my_custom_block")
*/
class MyCustomBlock extends AbstractBlock
{
// Add custom fields as needed
}
First Render: Pass a collection of blocks to Twig:
{% set blocks = app.doctrine.orm.entity_manager.getRepository('AppBundle:MyCustomBlock').findAll() %}
{{ cms_render(blocks) }}
Create a simple page with editable blocks:
Page entity with a OneToMany relation to MyCustomBlock.{% set page = app.doctrine.orm.entity_manager.getRepository('AppBundle:Page').find(1) %}
{{ cms_render(page.blocks, { is_editable: true }) }}
Entity Design:
AbstractBlock for each block type (e.g., TextBlock, ImageBlock).@ORM\Table and @ORM\Column annotations for custom fields./**
* @ORM\Column(type="string", nullable=true)
* @var string
*/
private $customField;
Block Types:
getType() in AbstractBlock:
public function getType()
{
return 'my_custom_type';
}
Rendering:
cms_render() in Twig with optional is_editable:
{{ cms_render(blocks, { is_editable: true, theme: 'MyBundle:Render:custom_theme.html.twig' }) }}
config (SirTrevor config) or assets (custom JS/CSS).Theming:
_blocks_theme.html.twig) by:
Resources/views/Render/blocks_theme.html.twig.edsi_tech_sir_trevor:
theme: 'MyBundle:Render:custom_theme.html.twig'
CRUD Operations:
findBy, findOneBy).$blocks = $entityManager->getRepository(MyCustomBlock::class)->findBy(['page' => $page]);
Dynamic Block Loading:
public function showAction(Page $page)
{
return $this->render('page/show.html.twig', [
'blocks' => $page->getBlocks(),
'is_editable' => $this->getUser()->hasRole('ROLE_EDITOR'),
]);
}
Asset Management:
edsi_tech_sir_trevor:
assets:
js: ['/bundles/mybundle/js/custom.js']
css: ['/bundles/mybundle/css/custom.css']
Block Type Mismatch:
getType() in AbstractBlock matches the SirTrevor JS block type. Mismatches cause rendering issues.SirTrevor errors if blocks fail to load.Twig Template Overrides:
_blocks_theme.html.twig requires the template to extend the base template:
{% extends 'EdsiTechSirTrevorBundle:Render:_blocks_theme.html.twig' %}
Doctrine Annotations:
AbstractBlock already includes basic annotations (id, type, content). Adding redundant annotations (e.g., @ORM\Id) may cause conflicts.Editable Mode:
is_editable: true requires SirTrevor JS to be loaded. Ensure the bundle’s assets are included in your base template or layout.Console Errors:
SirTrevor or EdsiTechSirTrevorBundle errors in the browser console. Common issues:
Symfony Profiler:
Log Block Data:
foreach ($blocks as $block) {
$this->get('logger')->info('Block type: ' . $block->getType());
}
Custom Block Fields:
AbstractBlock:
public function getCustomField()
{
return $this->customField;
}
public function setCustomField($value)
{
$this->customField = $value;
return $this;
}
SirTrevor Configuration:
{{ cms_render(blocks, {
is_editable: true,
config: {
'someOption': true,
'anotherOption': 'value'
}
}) }}
Performance:
$blocks = $entityManager->getRepository(MyCustomBlock::class)
->createQueryBuilder('b')
->where('b.page = :page')
->setParameter('page', $page)
->getQuery()
->getResult();
Testing:
public function testBlockRendering()
{
$block = new MyCustomBlock();
$block->setType('test_type');
$block->setContent('<p>Test</p>');
$twig = $this->get('twig');
$html = $twig->render('EdsiTechSirTrevorBundle:Render:_blocks_theme.html.twig', [
'blocks' => [$block],
'is_editable' => false,
]);
$this->assertStringContainsString('<p>Test</p>', $html);
}
Extending the Bundle:
EdsiTechSirTrevorBundle.services.yml:
services:
my_custom.block_type:
class: AppBundle\Entity\MyCustomBlock
tags:
- { name: edsi_tech_sir_trevor.block_type }
How can I help you explore Laravel packages today?