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 Admin Bundle Laravel Package

dovstone/blog-admin-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation Run the composer command in your project root:

    composer require dovstone/symfony-blog-admin
    

    Ensure Dovstone\BlogAdminBundle\DovstoneBlogAdminBundle is enabled in config/bundles.php.

  2. Database Migration Execute the bundle’s migrations:

    php bin/console doctrine:migrations:diff
    php bin/console doctrine:migrations:migrate
    
  3. First Use Case Access /admin/blog to see the default admin interface. The bundle provides CRUD for:

    • Posts (Post entity)
    • Categories (Category entity)
    • Users (if extended via User entity)

Implementation Patterns

Core Workflows

  1. Post Management

    • Create/Edit/Delete posts via the /admin/blog/post route.
    • Use the Post entity (src/Entity/Post.php) to extend fields (e.g., slug, meta_title).
    • Example custom field:
      // src/Entity/Post.php
      /**
       * @ORM\Column(type="string", length=255, nullable=true)
       */
      private $customField;
      
  2. Category Hierarchy

    • Categories support parent-child relationships (nested sets).
    • Modify the Category entity (src/Entity/Category.php) to add custom logic:
      // Add a method to fetch child categories
      public function getChildren(): Collection
      {
          return $this->children->matching(new Expression('parent = :parent'), [':parent' => $this]);
      }
      
  3. Frontend Integration

    • Fetch posts via the PostRepository:
      // src/Controller/BlogController.php
      public function index(PostRepository $repo): Response
      {
          $posts = $repo->findBy([], ['createdAt' => 'DESC']);
          return $this->render('blog/index.html.twig', ['posts' => $posts]);
      }
      
    • Use Twig to render posts:
      {% for post in posts %}
          <h2>{{ post.title }}</h2>
          <p>{{ post.content|truncate(200) }}</p>
      {% endfor %}
      
  4. Custom Controllers/Forms

    • Override default admin routes by extending the bundle’s controller:
      # config/routes.yaml
      dovstone_blog_admin_post:
          resource: "@DovstoneBlogAdminBundle/Resources/config/routing/post.yaml"
          type: annotation
          prefix: /admin/blog
      
    • Extend forms by creating a custom type:
      // src/Form/PostType.php
      class PostType extends AbstractType
      {
          public function buildForm(FormBuilderInterface $builder, array $options)
          {
              $builder->add('customField', TextType::class);
          }
      }
      

Gotchas and Tips

Pitfalls

  1. Outdated Doctrine Migrations

    • The bundle’s last release is from 2021-03-03. Ensure your doctrine/orm and doctrine/doctrine-bundle versions are compatible.
    • Manually check src/Resources/migrations/ for schema changes if extending entities.
  2. Hardcoded Routes

    • Admin routes are prefixed with /admin/blog. Override them in config/routes.yaml to avoid conflicts:
      dovstone_blog_admin:
          resource: "@DovstoneBlogAdminBundle/Resources/config/routing/admin.yaml"
          prefix: /custom-prefix
      
  3. Lack of Documentation

  4. Translation Issues

    • Translations are stored in Resources/translations/messages.en.xlf. Extend them by copying the file to translations/messages.en.xlf in your project.

Debugging Tips

  1. Entity Extensions

    • If extending Post or Category, clear the cache after changes:
      php bin/console cache:clear
      
  2. Form Validation

    • Validate custom fields in the entity:
      // src/Entity/Post.php
      public function getCustomField(): ?string
      {
          return $this->customField;
      }
      
      public function setCustomField(?string $customField): self
      {
          $this->customField = $customField;
          return $this;
      }
      
      // Add constraints in the form type
      $builder->add('customField', TextType::class, [
          'constraints' => [new Length(['max' => 100])],
      ]);
      
  3. Query Performance

    • Use PostRepository methods to optimize queries:
      // Avoid N+1 queries
      $posts = $repo->findBy([], ['createdAt' => 'DESC'], null, 10);
      

Extension Points

  1. Custom Admin Layout

    • Override the base template:
      {# templates/blog_admin/base.html.twig #}
      {% extends 'DovstoneBlogAdminBundle:layout.html.twig' %}
      {% block stylesheets %}
          {{ parent() }}
          {{ encore_entry_link_tags('admin-blog') }}
      {% endblock %}
      
  2. Event Listeners

    • Subscribe to post events (e.g., PostEvents::POST_PERSIST):
      // src/EventListener/PostListener.php
      class PostListener implements EventSubscriberInterface
      {
          public static function getSubscribedEvents()
          {
              return [
                  PostEvents::POST_PERSIST => 'onPostPersist',
              ];
          }
      
          public function onPostPersist(PostEvent $event)
          {
              $post = $event->getPost();
              // Add logic (e.g., generate slug)
              $post->setSlug(Str::slug($post->getTitle()));
          }
      }
      
  3. API Integration

    • Expose posts via API using Symfony’s Serializer:
      // src/Controller/ApiPostController.php
      #[Route('/api/posts', methods: ['GET'])]
      public function index(PostRepository $repo, SerializerInterface $serializer): JsonResponse
      {
          $posts = $repo->findAll();
          return new JsonResponse($serializer->serialize($posts, 'json', ['groups' => '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