7rin0/bigfoot-content-bundle
Installation
Add the bundle to your composer.json:
composer require 7rin0/bigfoot-content-bundle
Register the bundle in config/bundles.php:
return [
// ...
SevenRin0\BigfootContentBundle\BigfootContentBundle::class => ['all' => true],
];
Database Migration Run migrations to set up the required tables:
php bin/console doctrine:migrations:diff
php bin/console doctrine:migrations:migrate
First Use Case: Creating a Content Type
Define a new content type in YAML (e.g., config/bigfoot/content_types/article.yml):
article:
label: Article
fields:
title: { type: text, required: true }
body: { type: html, required: true }
Register the config in config/packages/bigfoot_content.yaml:
seven_rin0_bigfoot_content:
content_types:
- '%kernel.project_dir%/config/bigfoot/content_types/article.yml'
Basic CRUD via CLI Create a new content entry:
php bin/console bigfoot:content:create article --title="My Article" --body="<p>Content here</p>"
List all entries:
php bin/console bigfoot:content:list article
Content Type Definition
page, blog_post, product).product type:
product:
label: Product
fields:
sku: { type: text, required: true, unique: true }
price: { type: decimal, scale: 2 }
images: { type: file, multiple: true }
Integration with Symfony Forms Generate a form dynamically in a controller:
use SevenRin0\BigfootContentBundle\Form\ContentTypeFormFactory;
class ContentController extends AbstractController
{
public function new(ContentTypeFormFactory $formFactory, string $type)
{
$form = $formFactory->createForm($type);
// ...
}
}
Data Access Fetch entries via Doctrine repository:
$repository = $this->getDoctrine()->getRepository(ContentEntry::class);
$articles = $repository->findBy(['type' => 'article'], ['createdAt' => 'DESC']);
Event Listeners
Hook into lifecycle events (e.g., prePersist, postUpdate) via Symfony’s event dispatcher:
# config/services.yaml
services:
App\EventListener\ContentListener:
tags:
- { name: kernel.event_listener, event: bigfoot.content.pre_save, method: onPreSave }
API Endpoints Expose content via API Platform or FOSRestBundle:
# config/api_platform/resources.yaml
resources:
SevenRin0\BigfootContentBundle\Entity\ContentEntry:
collectionOperations:
get:
method: GET
path: /content/{type}
vich/uploader-bundle for file uploads:
fields:
image: { type: file, vich_uploader: true }
fields:
email: { type: text, validation: { email: true } }
$cache = $this->container->get('cache.app');
$contentType = $cache->get('content_type_article', function() use ($em) {
return $em->find(ContentType::class, 'article');
});
Content Type Caching
php bin/console cache:clear
bigfoot:content:reload to force reload:
php bin/console bigfoot:content:reload
Field Type Mismatches
decimal → decimal(10,2)). Mismatches cause:
[Doctrine\DBAL\DBALException] An exception occurred while executing '...'
bigfoot:content:validate:
php bin/console bigfoot:content:validate
Unique Constraints
unique: true (e.g., sku) require a unique index in the database. Add via migration:
$this->addSql('CREATE UNIQUE INDEX idx_content_entry_sku ON content_entry(sku)');
File Uploads
vich/uploader-bundle, file fields (type: file) will fail silently. Configure uploads in config/packages/vich_uploader.yaml:
db_driver: orm
mappings:
content_images:
uri_prefix: /uploads/content
upload_destination: '%kernel.project_dir%/public/uploads/content'
Symfony 4+ Compatibility
symfony/flex to auto-configure bundles.ContentTypeManager):
# config/services.yaml
SevenRin0\BigfootContentBundle\Manager\ContentTypeManager: ~
Log Content Type Loading Enable debug mode and check logs for parsing errors:
php bin/console debug:config seven_rin0_bigfoot_content
Look for ContentTypeLoader errors in var/log/dev.log.
Dump Field Schema Inspect the generated schema for a content type:
$schema = $this->get('bigfoot.content.schema_factory')->createSchema('article');
dump($schema->getFieldDefinitions());
Common Errors
bigfoot_content.yaml and run bigfoot:content:reload./_profiler).Custom Field Types
Extend SevenRin0\BigfootContentBundle\Form\Type\AbstractFieldType to add custom fields (e.g., color_picker):
class ColorPickerType extends AbstractFieldType
{
public function getParent()
{
return TextType::class;
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(['attr' => ['class' => 'color-picker']]);
}
}
Register in config/packages/bigfoot_content.yaml:
seven_rin0_bigfoot_content:
custom_field_types:
color_picker: App\Form\Type\ColorPickerType
Dynamic Content Types Load content types dynamically from a database:
// Override ContentTypeLoader
class DatabaseContentTypeLoader implements ContentTypeLoaderInterface
{
public function load(): array
{
return $this->entityManager->getRepository(ContentType::class)->findAll();
}
}
Bind the service in config/services.yaml:
services:
SevenRin0\BigfootContentBundle\Loader\ContentTypeLoader:
alias: App\Loader\DatabaseContentTypeLoader
Twig Extensions Add Twig filters for content rendering:
class ContentTwigExtension extends \Twig\Extension\AbstractExtension
{
public function getFilters()
{
return [
new \Twig\TwigFilter('render_content', [$this, 'renderContent']),
];
}
public function renderContent($entry, $field)
{
return $entry->getField($field)->getRenderedValue();
}
}
Register in config/packages/twig.yaml:
twig:
extensions:
- App\Twig\ContentTwigExtension
How can I help you explore Laravel packages today?