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

Blog Bundle Laravel Package

avro/blog-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation Add the bundle to your composer.json:

    composer require avro/blog-bundle
    

    Enable it in config/bundles.php:

    return [
        // ...
        Avro\BlogBundle\AvroBlogBundle::class => ['all' => true],
    ];
    
  2. Configuration Add the required config to config/packages/avro_blog.yaml:

    avro_blog:
        db_driver: mongodb  # Only supported option
        list_count: 10      # Posts per page
    
  3. Routing Import routes in config/routes.yaml:

    avro_blog:
        resource: "@AvroBlogBundle/Resources/config/routing/routing.yml"
    
  4. First Use Case

    • Visit /blog to see a paginated list of posts.
    • Use the admin interface (if exposed) to create/edit posts via MongoDB.

Implementation Patterns

Core Workflows

  1. Post Management

    • CRUD via Admin: If the bundle exposes an admin interface (likely via KnpPaginator), use it for:
      // Example (hypothetical) service call to create a post
      $this->get('avro_blog.post_manager')->create([
          'title' => 'Hello World',
          'content' => '...',
          'published_at' => new \DateTime(),
      ]);
      
    • Manual Entity Handling: Extend Avro\BlogBundle\Entity\Post (if available) to add custom fields:
      use Avro\BlogBundle\Entity\Post as BasePost;
      
      class ExtendedPost extends BasePost {
          /**
           * @ORM\Column(type="string", nullable=true)
           */
          private $customField;
      }
      
  2. Pagination

    • Leverage KnpPaginatorBundle for custom pagination logic:
      use Knp\Component\Pager\PaginatorInterface;
      
      $posts = $this->get('knp_paginator')->paginate(
          $this->get('avro_blog.post_repository')->findAll(),
          $this->getParameter('avro_blog.list_count')
      );
      
  3. Templating

    • Override default templates in templates/blog/:
      {# app/Resources/AvroBlogBundle/views/Post/index.html.twig #}
      {% extends 'AvroBlogBundle:Post:index.html.twig' %}
      {% block post_content %}
          {{ post.content|raw }} <!-- Customize rendering -->
      {% endblock %}
      
  4. Event Listeners

    • Subscribe to post events (if the bundle dispatches them):
      // src/EventListener/BlogListener.php
      class BlogListener {
          public function onPostPublish(PostPublishEvent $event) {
              // Add logic (e.g., send notification)
          }
      }
      
      Register in services.yaml:
      services:
          App\EventListener\BlogListener:
              tags:
                  - { name: 'kernel.event_listener', event: 'avro_blog.post_publish' }
      

Gotchas and Tips

Pitfalls

  1. MongoDB Dependency

    • The bundle only supports MongoDB. If you need SQL, avoid this package or fork it.
    • Ensure your doctrine_mongodb bundle is properly configured:
      doctrine_mongodb:
          connections:
              default:
                  server: '%mongodb_uri%'
                  options: {}
      
  2. Lack of Documentation

    • No clear API docs or event system. Expect to inspect:
      • src/Resources/config/routing/routing.yml for route paths.
      • src/Entity/Post.php for entity structure.
      • src/DependencyInjection/ for configuration logic.
  3. No Active Maintenance

    • "Under development and may break" warning in the README. Test thoroughly in staging.
  4. KnpPaginatorBundle Dependency

    • Ensure knp-paginator-bundle is installed and configured:
      composer require knplabs/knp-paginator-bundle
      

Debugging Tips

  1. Check Routes Dump available routes to verify integration:

    php bin/console debug:router | grep avro_blog
    
  2. MongoDB Queries Log queries to debug issues:

    doctrine_mongodb:
        logging: true
    
  3. Template Overrides Clear cache after overriding templates:

    php bin/console cache:clear
    

Extension Points

  1. Custom Post Fields Extend the Post entity (if possible) or create a one-to-one relationship:

    // src/Entity/CustomPostData.php
    class CustomPostData {
        // Add fields here
    }
    

    Link it to the post entity:

    // In Post.php
    /**
     * @ORM\OneToOne(targetEntity="CustomPostData", mappedBy="post", cascade={"persist", "remove"})
     */
    private $customData;
    
  2. Custom Repository Override the default repository for complex queries:

    // src/Repository/CustomPostRepository.php
    class CustomPostRepository extends ServiceEntityRepository {
        public function findPublishedWithTags(string $tag) {
            // Custom logic
        }
    }
    

    Update services.yaml:

    services:
        Avro\BlogBundle\Repository\PostRepository:
            alias: 'App\Repository\CustomPostRepository'
    
  3. Event Dispatching If the bundle lacks events, create your own:

    // src/Event/PostEvent.php
    class PostEvent extends Event {
        protected $post;
        // ...
    }
    

    Dispatch manually in controllers/services:

    $event = new PostEvent($post);
    $this->get('event_dispatcher')->dispatch($event, 'avro_blog.post_publish');
    
  4. Form Integration If the bundle uses forms, extend them:

    // src/Form/PostTypeExtension.php
    class PostTypeExtension extends AbstractTypeExtension {
        public function buildForm(FormBuilderInterface $builder, array $options) {
            $builder->add('customField', TextType::class);
        }
    }
    

    Register the extension:

    services:
        App\Form\Extension\PostTypeExtension:
            tags:
                - { name: form.type_extension, extended_type: Avro\BlogBundle\Form\PostType }
    
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