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

Bigfoot Content Bundle Laravel Package

7rin0/bigfoot-content-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. 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],
    ];
    
  2. Database Migration Run migrations to set up the required tables:

    php bin/console doctrine:migrations:diff
    php bin/console doctrine:migrations:migrate
    
  3. 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'
    
  4. 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
    

Implementation Patterns

Workflow: Content Management

  1. Content Type Definition

    • Use YAML/XML/Annotation to define reusable content types (e.g., page, blog_post, product).
    • Example for a product type:
      product:
          label: Product
          fields:
              sku: { type: text, required: true, unique: true }
              price: { type: decimal, scale: 2 }
              images: { type: file, multiple: true }
      
  2. 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);
            // ...
        }
    }
    
  3. Data Access Fetch entries via Doctrine repository:

    $repository = $this->getDoctrine()->getRepository(ContentEntry::class);
    $articles = $repository->findBy(['type' => 'article'], ['createdAt' => 'DESC']);
    
  4. 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 }
    
  5. 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}
    

Integration Tips

  • Localization: Use Symfony’s translation system to support multilingual content fields.
  • Media Handling: Pair with vich/uploader-bundle for file uploads:
    fields:
        image: { type: file, vich_uploader: true }
    
  • Validation: Extend field validation with Symfony’s constraints:
    fields:
        email: { type: text, validation: { email: true } }
    
  • Caching: Cache content types and entries with Symfony’s cache component:
    $cache = $this->container->get('cache.app');
    $contentType = $cache->get('content_type_article', function() use ($em) {
        return $em->find(ContentType::class, 'article');
    });
    

Gotchas and Tips

Pitfalls

  1. Content Type Caching

    • Changes to YAML/XML content type definitions do not auto-update. Clear the cache after modifying:
      php bin/console cache:clear
      
    • Use bigfoot:content:reload to force reload:
      php bin/console bigfoot:content:reload
      
  2. Field Type Mismatches

    • Ensure field types in YAML match Doctrine DBAL types (e.g., decimaldecimal(10,2)). Mismatches cause:
      [Doctrine\DBAL\DBALException] An exception occurred while executing '...'
      
    • Solution: Validate with bigfoot:content:validate:
      php bin/console bigfoot:content:validate
      
  3. Unique Constraints

    • Fields marked as 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)');
      
  4. File Uploads

    • Without 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'
      
  5. Symfony 4+ Compatibility

    • The bundle targets Symfony 3. For Symfony 4/5:
      • Use symfony/flex to auto-configure bundles.
      • Override autowiring if needed (e.g., ContentTypeManager):
        # config/services.yaml
        SevenRin0\BigfootContentBundle\Manager\ContentTypeManager: ~
        

Debugging

  1. 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.

  2. Dump Field Schema Inspect the generated schema for a content type:

    $schema = $this->get('bigfoot.content.schema_factory')->createSchema('article');
    dump($schema->getFieldDefinitions());
    
  3. Common Errors

    • "Content type not found": Verify the YAML path in bigfoot_content.yaml and run bigfoot:content:reload.
    • Form submission fails: Check for missing CSRF tokens or validation errors in Symfony’s profiler (/_profiler).

Extension Points

  1. 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
    
  2. 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
    
  3. 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
    
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