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

Content Bundle Laravel Package

axstrad/content-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation

    composer require axstrad/content-bundle
    

    Add to AppKernel.php:

    new Axstrad\ContentBundle\AxstradContentBundle(),
    
  2. First Use Case: Basic Content Model Define a content entity (e.g., BlogPost) extending Axstrad\ContentBundle\Entity\Content:

    use Axstrad\ContentBundle\Entity\Content;
    
    class BlogPost extends Content
    {
        // Custom fields/methods
    }
    

    Run migrations:

    php app/console doctrine:schema:update --force
    
  3. Twig Integration Enable Twig extensions in config.yml:

    twig:
        extensions: [Axstrad\ContentBundle\Twig\ContentExtension]
    

    Use in templates:

    {{ content('BlogPost', 1).title }}
    

Implementation Patterns

Core Workflows

  1. CRUD Operations Use repository methods:

    $repository = $this->getDoctrine()->getRepository('AxstradContentBundle:BlogPost');
    $post = $repository->find(1); // Get by ID
    $posts = $repository->findBy(['status' => 'published']); // Query builder
    
  2. Content Types & Inheritance Extend Content for reusable logic:

    class Product extends Content
    {
        protected $price;
        // ...
    }
    
  3. Twig Content Rendering Dynamic content blocks:

    {% for block in content('Page', 1).blocks %}
        {{ block.render() }}
    {% endfor %}
    
  4. API Integration Use Axstrad\ContentBundle\Serializer\ContentNormalizer for API responses:

    $serializer->serialize($content, 'json');
    

Integration Tips

  • Doctrine Events: Subscribe to prePersist/preUpdate for validation:
    $entityManager->getEventManager()->addEventListener(
        ContentEvents::PRE_PERSIST,
        [$this, 'validateContent']
    );
    
  • Fixtures: Load test data via doctrine-fixtures-bundle:
    $fixture->addReference('homepage', new Page(['title' => 'Home']));
    

Gotchas and Tips

Pitfalls

  1. Legacy Symfony 2.3 Dependency

    • Issue: Requires Symfony 2.3.x (not compatible with Symfony 3+).
    • Workaround: Use a wrapper or fork for newer Symfony versions.
  2. Twig Extension Conflicts

    • Issue: Namespace collisions with other ContentExtension classes.
    • Fix: Alias the Twig extension in config.yml:
      twig:
          extensions:
              - ['Axstrad\ContentBundle\Twig\ContentExtension', 'axstrad_content']
      
  3. Missing Soft Deletes

    • Issue: No built-in soft-delete support.
    • Tip: Extend Content and add deletedAt field manually.

Debugging

  • Query Debugging: Enable Doctrine profiling:
    $this->getDoctrine()->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger());
    
  • Content Dumps: Use var_dump($content->toArray()) for debugging entity structure.

Extension Points

  1. Custom Fields Add dynamic fields via addField() in entity constructors:

    public function __construct()
    {
        $this->addField('metaDescription', 'string');
    }
    
  2. Content Events Extend ContentEvents for custom logic:

    class MyContentListener
    {
        public function onContentPublish(ContentEvent $event)
        {
            // Logic on publish
        }
    }
    
  3. Serializer Groups Override normalization groups in config.yml:

    axstrad_content:
        serializer:
            groups: [default, 'api']
    
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.
comsave/common
alecsammon/php-raml-parser
chrome-php/wrench
lendable/composer-license-checker
typhoon/reflection
mesilov/moneyphp-percentage
mike42/gfx-php
bookdown/themes
aura/view
aura/html
aura/cli
povils/phpmnd
nayjest/manipulator
omnipay/tests
psr-mock/http-message-implementation
psr-mock/http-factory-implementation
psr-mock/http-client-implementation
voku/email-check
voku/urlify
rtheunissen/guzzle-log-middleware