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

Core Bundle Laravel Package

dywee/core-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation

    composer require dywee/core-bundle
    

    Register the bundle in config/bundles.php:

    return [
        // ...
        Dywee\CoreBundle\DyweeCoreBundle::class => ['all' => true],
    ];
    
  2. First Use Case: Admin Template Extend the base admin.html.twig template in your bundle’s Resources/views/:

    {# src/YourBundle/Resources/views/admin.html.twig #}
    {% extends "DyweeCoreBundle:Templates:admin.html.twig" %}
    
    {% block metaTitle %}{{ parent() }} - Custom Title{% endblock %}
    {% block body %}
        <h1>Welcome to Your Admin Panel</h1>
    {% endblock %}
    
  3. Key Files to Explore

    • DyweeCoreBundle/Resources/views/Templates/admin.html.twig (base template).
    • Event/SidebarBuilderEvent.php, DashboardBuilderEvent.php, AdminNavbarBuilderEvent.php (event classes).

Implementation Patterns

1. Admin Template Inheritance

  • Workflow: Override blocks (metaTitle, body, sidebar, etc.) in your child template.
  • Example:
    {% block sidebar %}
        {{ parent() }}  {# Renders parent sidebar #}
        <li><a href="{{ path('your_route') }}">Custom Link</a></li>
    {% endblock %}
    

2. Event-Driven Customization

  • Pattern: Subscribe to events to dynamically modify the admin UI.
  • Example Listener:
    namespace App\EventListener;
    
    use Dywee\CoreBundle\Event\SidebarBuilderEvent;
    use Symfony\Component\EventDispatcher\EventSubscriberInterface;
    
    class AdminSidebarSubscriber implements EventSubscriberInterface
    {
        public static function getSubscribedEvents()
        {
            return [
                SidebarBuilderEvent::class => 'onSidebarBuild',
            ];
        }
    
        public function onSidebarBuild(SidebarBuilderEvent $event)
        {
            $sidebar = $event->getSidebar();
            $sidebar->addItem('dashboard', 'Dashboard', 'fa fa-dashboard');
            $event->setSidebar($sidebar);
        }
    }
    
  • Register the listener in services.yaml:
    services:
        App\EventListener\AdminSidebarSubscriber:
            tags: ['kernel.event_subscriber']
    

3. ParentController Integration

  • Use Case: Extend Dywee\CoreBundle\Controller\ParentController for CRUD actions.
  • Example:
    namespace App\Controller;
    
    use Dywee\CoreBundle\Controller\ParentController;
    
    class PostController extends ParentController
    {
        public function indexAction()
        {
            return $this->render('App:Post:index.html.twig');
        }
    }
    

4. JS Form Collections

  • Pattern: Use the bundle’s JS helpers for dynamic form collections (e.g., nested models).
  • Example Twig:
    {{ form_start(form) }}
        {{ form_widget(form) }}
        <button type="button" class="add-item">Add Item</button>
    {{ form_end(form) }}
    
    <script>
        // Bundle provides JS for dynamic collection handling
        $('.add-item').click(function() {
            // Leverages Dywee's JS collection logic
            DyweeFormCollection.addItem('{{ form.vars.id }}');
        });
    </script>
    

Gotchas and Tips

Pitfalls

  1. Event Dispatcher Typos

    • Issue: Forgetting EventDispatcher (note the British spelling in the README: EventDispatc).
    • Fix: Use Symfony\Component\EventDispatcher\EventDispatcherInterface.
  2. Template Block Overrides

    • Issue: Forgetting {{ parent() }} in blocks can break inheritance.
    • Fix: Always call parent() if extending functionality.
  3. JS Collection Dependencies

    • Issue: Missing jQuery or bundle-specific JS assets.
    • Fix: Ensure dywee-core-bundle JS assets are enqueued in your base template:
      {{ parent() }}  {# In your admin.html.twig #}
      {{ dywee_core_js() }}  {# Hypothetical helper; check bundle docs #}
      

Debugging Tips

  1. Event Debugging

    • Dump event objects to inspect available methods:
      public function onSidebarBuild(SidebarBuilderEvent $event)
      {
          dump($event->getSidebar()->getItems());
      }
      
  2. Template Hierarchy

    • Use Twig’s {% debug %} to trace template inheritance:
      {% debug %}
      
  3. Admin LTE Customization

    • Tip: Override admin_lte.html.twig (if provided) for deeper theming:
      {% extends "DyweeCoreBundle:Templates:admin_lte.html.twig" %}
      {% block stylesheets %}
          {{ parent() }}
          <link rel="stylesheet" href="{{ asset('css/custom.css') }}">
      {% endblock %}
      

Extension Points

  1. Custom Events

    • Extend existing events or create new ones by implementing DyweeCoreEvent.
  2. Controller Traits

    • Reuse ParentController logic via traits:
      use Dywee\CoreBundle\Controller\Traits\CrudTrait;
      
  3. Asset Management

    • Override bundle assets by copying files to web/bundles/dyweecore/ (Symfony’s asset override convention).
  4. Data Preload for Modals

    • Use Case: Fetch remote data for modals via AJAX.
    • Example Route:
      // src/Controller/ModalController.php
      class ModalController extends ParentController
      {
          public function preloadDataAction($id)
          {
              $data = $this->getDataForModal($id);
              return $this->json($data);
          }
      }
      
    • Twig Integration:
      <a href="#" class="remote-modal" data-url="{{ path('modal_preload', {'id': item.id}) }}">
          Open Modal
      </a>
      
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