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

Cms Bundle Laravel Package

devtronic/cms-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

First Steps

  1. Installation Run composer require --dev devtronic/cms-bundle and enable the bundle in AppKernel.php (Symfony 2/3). For Symfony 3.x, execute:

    php bin/console assets:install --symlink --relative
    php bin/console doctrine:schema:update --force
    php bin/console cache:clear
    
  2. Basic Configuration Add routing in app/config/routing.yml:

    devtronic_cms_bundle:
        resource: "@CmsBundle/Controller/"
        type: annotation
        prefix: /cms
    
  3. First Use Case Display a menu in a Twig template:

    {{ cms_menu("main_menu") }}
    

    Ensure a menu with slug main_menu exists in the Sonata Admin panel (accessible at /admin).


Implementation Patterns

Core Workflows

  1. Menu Management

    • Use Sonata Admin (/admin) to create Menu, MenuItem, and Page entities.
    • Assign slugs to menus (e.g., main_menu, footer_links) for Twig integration.
    • Dynamically render menus in templates with {{ cms_menu("SLUG") }}.
  2. Page Content Rendering

    • Pages are stored as Page entities with slugs (e.g., about-us).
    • Access page content via:
      {{ cms_page("about-us").content }}
      
    • Use IvoryCKEditorBundle (required dependency) for WYSIWYG editing.
  3. Dynamic Menu Templates Override default menu templates by extending:

    {% extends "DevtronicCmsBundle:Menu:default.html.twig" %}
    

    Place custom templates in app/Resources/DevtronicCmsBundle/views/Menu/.

  4. Routing Integration

    • Pages are auto-routed via the prefix in routing.yml (e.g., /cms/about-us).
    • Extend routing with custom logic in app/config/routing.yml:
      cms_homepage:
          path: /
          defaults: { _controller: "CmsBundle:Page:show", slug: "home" }
      
  5. Sonata Admin Customization

    • Extend MenuAdmin, MenuItemAdmin, or PageAdmin for additional fields:
      // src/AppBundle/Admin/MenuAdmin.php
      use Devtronic\CmsBundle\Admin\MenuAdmin as BaseMenuAdmin;
      
      class MenuAdmin extends BaseMenuAdmin {
          protected function configureFormFields(FormMapper $formMapper) {
              $formMapper->add('custom_field', 'text');
          }
      }
      

Gotchas and Tips

Pitfalls

  1. Outdated Dependencies

    • The bundle is archived (last release: 2017) and lacks Symfony 4/5+ support.
    • Workaround: Use a compatibility layer (e.g., symfony/symfony:3.*) or fork the repo.
  2. Missing Multi-Language Support

    • The "Open" section of the README confirms no built-in i18n for content.
    • Workaround: Implement custom translations via trans() in Twig or a separate table.
  3. Asset Pipeline Issues

    • Assets may fail to install if assets:install is skipped.
    • Fix: Run php bin/console assets:install --symlink after updates.
  4. Sonata Admin Conflicts

    • If Sonata Admin is not installed, the bundle’s CRUD features break.
    • Solution: Install sonata-project/admin-bundle first.
  5. Doctrine Schema Updates

    • Running --force on doctrine:schema:update may overwrite existing data.
    • Tip: Backup the database before migrations.

Debugging Tips

  • Check Menu Slugs: Verify slugs in Sonata Admin match those in Twig (case-sensitive).
  • Clear Cache: Run cache:clear after config changes or bundle updates.
  • Log Errors: Enable debug mode (APP_DEBUG=true) for Twig/Doctrine errors.
  • Template Overrides: Ensure custom templates are placed in the correct namespace (DevtronicCmsBundle).

Extension Points

  1. Custom Menu Rendering Override the MenuType service to modify menu logic:

    # app/config/services.yml
    services:
        devtronic_cms.menu.type.custom:
            class: AppBundle\Twig\Extension\CustomMenuExtension
            tags:
                - { name: twig.extension }
    
  2. Page Content Processing Extend the Page entity to add custom fields or behaviors:

    // src/AppBundle/Entity/PageExtension.php
    use Devtronic\CmsBundle\Entity\Page as BasePage;
    
    class PageExtension extends BasePage {
        private $metaTitle;
        // Add getters/setters and Doctrine lifecycle callbacks.
    }
    
  3. Event Listeners Hook into CMS events (e.g., cms.menu.build) via Symfony’s event dispatcher:

    // src/AppBundle/EventListener/CmsListener.php
    use Devtronic\CmsBundle\Event\MenuBuildEvent;
    
    class CmsListener {
        public function onMenuBuild(MenuBuildEvent $event) {
            $event->addItem('custom_item', ['route' => 'some_route']);
        }
    }
    

    Register in services.yml:

    services:
        app.cms_listener:
            class: AppBundle\EventListener\CmsListener
            tags:
                - { name: kernel.event_listener, event: cms.menu.build, method: onMenuBuild }
    
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