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

ekyna/cms-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Steps

  1. Installation:

    composer require ekyna/cms-bundle
    

    Add to config/bundles.php:

    Ekyna\CmsBundle\EkynaCmsBundle::class => ['all' => true],
    
  2. Basic Setup:

    • Configure routes in app/config/routing.yml to attach SEO/content:
      ekyna_cms:
          resource: "@EkynaCmsBundle/Resources/config/routing.yml"
          prefix:   /
      
    • Define a static route in app/config/routing.yml (e.g., homepage):
      homepage:
          path: /
          defaults: { _controller: AppController::homepageAction }
      
  3. First Use Case:

    • Create a CMS page via the ekyna_admin bundle (if installed) or manually via the ekyna_cms:page:create command:
      php bin/console ekyna_cms:page:create homepage --title="Welcome" --content="<h1>Hello!</h1>"
      
    • Access the page at / with dynamic content rendered.

Implementation Patterns

Core Workflows

  1. Attaching SEO/Content to Routes:

    • Use the ekyna_cms.page entity to link content to Symfony routes.
    • Example in a controller:
      use Ekyna\CmsBundle\Entity\Page;
      
      public function homepageAction(Request $request, Page $page)
      {
          return $this->render('homepage.html.twig', [
              'content' => $page->getContent(),
              'meta_title' => $page->getMetaTitle(),
          ]);
      }
      
    • Twig Integration:
      {{ page.content|raw }}  {# Render HTML content #}
      
  2. Responsive Layouts (Bootstrap 3):

    • Define layouts in app/Resources/EkynaCmsBundle/views/layouts/ (e.g., default.html.twig).
    • Extend layouts in templates:
      {% extends 'EkynaCmsBundle::layouts/default.html.twig' %}
      {% block content %}{{ parent() }}{{ page.content|raw }}{% endblock %}
      
  3. Child Routes (with AdminBundle):

    • Create nested routes under static ones via the admin interface (if ekyna/AdminBundle is installed).
    • Example: /blog (static) → /blog/post-1 (dynamic child).
  4. Command-Line Management:

    • Create/update pages:
      php bin/console ekyna_cms:page:create blog --title="Blog" --content="..."
      php bin/console ekyna_cms:page:update blog --content="Updated content"
      

Integration Tips

  • Symfony Forms: Use Ekyna\CmsBundle\Form\Type\PageType for CMS content editing.
  • Doctrine: Extend Page entity to add custom fields (e.g., author, publishDate).
  • Events: Listen to ekyna_cms.page.pre_save to modify content before saving.
    // src/EventListener/CmsListener.php
    public function onPreSave(PreSaveEvent $event) {
        $page = $event->getPage();
        $page->setMetaDescription('Default description');
    }
    
    Register in services.yml:
    services:
        App\EventListener\CmsListener:
            tags:
                - { name: kernel.event_listener, event: ekyna_cms.page.pre_save }
    

Gotchas and Tips

Pitfalls

  1. Outdated Dependencies:

    • The bundle was last updated in 2015 and assumes Symfony 2.x. Test thoroughly with Symfony 4/5/6 using compatibility layers (e.g., symfony/symfony:^2.7 in composer.json).
    • Fix: Use a compatibility bridge or fork the bundle.
  2. Missing AdminBundle:

    • Child route management requires ekyna/AdminBundle. Without it, use the CLI or manually create Page entities via Doctrine.
  3. Twig Auto-escaping:

    • The page.content is rendered with |raw, which bypasses Twig’s auto-escaping. Sanitize content if user-generated:
      {{ page.content|striptags|raw }}  {# Remove HTML tags #}
      
  4. Route Overrides:

    • Static routes in routing.yml must precede dynamic CMS routes to avoid conflicts. Example:
      # app/config/routing.yml
      _cms:
          resource: "@EkynaCmsBundle/Resources/config/routing.yml"
          prefix: /
      homepage:
          path: /
          defaults: { _controller: AppController::homepageAction }
      
  5. Database Migrations:

    • The bundle creates its own tables (ekyna_cms_page). Ensure migrations are run:
      php bin/console doctrine:migrations:execute
      

Debugging

  • 404 Errors:

    • Verify the Page entity is linked to the route via page.route (e.g., homepage).
    • Check ekyna_cms.page.find_by_route in the database.
  • Content Not Rendering:

    • Clear the cache:
      php bin/console cache:clear
      
    • Ensure the Twig template extends the CMS layout.
  • Bootstrap Conflicts:

    • If using a custom Bootstrap version, override the CMS layout in app/Resources/EkynaCmsBundle/views/layouts/default.html.twig.

Extension Points

  1. Custom Fields:

    • Extend the Page entity:
      // src/Entity/ExtendedPage.php
      use Ekyna\CmsBundle\Entity\Page;
      class ExtendedPage extends Page {
          private $customField;
          // Add getters/setters and Doctrine annotations.
      }
      
    • Update the form type in EkynaCmsBundle/Form/Type/PageType.php.
  2. Custom Layouts:

    • Override the default layout by copying EkynaCmsBundle::layouts/default.html.twig to app/Resources/EkynaCmsBundle/views/layouts/.
  3. Event System:

    • Extend with custom events (e.g., ekyna_cms.page.post_publish):
      // src/Event/CustomEvent.php
      class CustomEvent extends Event {
          public function __construct(Page $page) { ... }
      }
      
    • Dispatch in a subscriber:
      public function onPostPublish(PostPublishEvent $event) {
          $this->eventDispatcher->dispatch(new CustomEvent($event->getPage()));
      }
      
  4. CLI Commands:

    • Extend the bundle’s commands (e.g., add a publish flag):
      // src/Command/CustomCommand.php
      class CustomCommand extends ContainerAwareCommand {
          protected function configure() {
              $this->setName('ekyna_cms:page:publish');
          }
          protected function execute(InputInterface $input, OutputInterface $output) {
              // Logic to publish a page.
          }
      }
      
    • Register in services.yml:
      commands:
          App\Command\CustomCommand:
              tags: ['console.command']
      
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