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

Pageedit Bundle Laravel Package

c975l/pageedit-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation

    composer require c975l/pageedit-bundle
    

    Add to bundles.php (Laravel 5.5+ uses config/app.php):

    return [
        // ...
        \C975L\PageEditBundle\C975LPageEditBundle::class,
    ];
    
  2. Publish Assets Run:

    php artisan vendor:publish --tag=pageedit-assets
    

    This copies TinyMCE, jQuery, and Bootstrap assets to public/bundles/c975lpageedit/.

  3. Configure Routes Add routing in routes/web.php:

    use C975L\PageEditBundle\Controller\PageEditController;
    
    $router->mount('/_pageedit', PageEditController::class)
        ->methods(['GET', 'POST'])
        ->bind('pageedit');
    
  4. First Use Case Edit a Twig template (e.g., resources/views/homepage.html.twig) and access it via:

    http://your-app.test/_pageedit/path/to/homepage
    

    The page will render with an inline TinyMCE editor for editable regions (wrapped in {% block editable %}).


Implementation Patterns

Core Workflow

  1. Mark Editable Regions Use Twig blocks to define editable content:

    {% block editable %}
        <h1>{{ block.content|default('Default Title') }}</h1>
        <p>{{ block.content|default('Default paragraph.') }}</p>
    {% endblock %}
    
  2. Template Protection Place templates in templates/protected/ to prevent edits via the UI. These remain editable via code.

  3. Versioning The bundle auto-archives old versions of edited files in var/pageedit_archive/. Retrieve past versions via:

    $archive = $this->get('c975l_pageedit.archive');
    $oldContent = $archive->getVersion('path/to/file', 1); // Version 1
    
  4. Sitemap Integration Generate a sitemap.xml dynamically in a controller:

    use C975L\PageEditBundle\Service\SitemapService;
    
    $sitemap = $this->get(SitemapService::class);
    $xml = $sitemap->generate([
        '/home' => ['changefreq' => 'daily', 'priority' => 0.9],
        '/about' => ['changefreq' => 'weekly', 'priority' => 0.5],
    ]);
    
  5. PDF Generation Convert a page to PDF in a controller:

    use C975L\PageEditBundle\Service\PdfService;
    
    $pdfService = $this->get(PdfService::class);
    $pdfContent = $pdfService->generate('path/to/page');
    file_put_contents('path/to/output.pdf', $pdfContent);
    

Integration Tips

  • Asset Management Override default assets by publishing and extending the pageedit template in your theme:

    php artisan vendor:publish --tag=pageedit-assets --force
    

    Then extend resources/views/bundles/c975lpageedit/base.html.twig.

  • Authentication Secure the _pageedit route with middleware (e.g., auth or custom roles):

    $router->mount('/_pageedit', PageEditController::class)
        ->methods(['GET', 'POST'])
        ->bind('pageedit')
        ->middleware('auth');
    
  • Custom Editors Extend TinyMCE configuration by overriding the tinymce_config.json asset:

    // public/bundles/c975lpageedit/tinymce_config.json
    {
        "plugins": ["advlist autolink lists link charmap print preview anchor"],
        "toolbar": "undo redo | bold italic bullist numlist"
    }
    
  • Event Listeners Hook into page save events to trigger custom logic (e.g., notifications):

    // src/EventListener/PageEditListener.php
    namespace App\EventListener;
    
    use C975L\PageEditBundle\Event\PageEditEvent;
    use Symfony\Component\EventDispatcher\EventSubscriberInterface;
    
    class PageEditListener implements EventSubscriberInterface
    {
        public static function getSubscribedEvents()
        {
            return [
                'pageedit.save' => 'onPageSave',
            ];
        }
    
        public function onPageSave(PageEditEvent $event)
        {
            // Custom logic (e.g., log changes, send email)
        }
    }
    

    Register in services.yaml:

    services:
        App\EventListener\PageEditListener:
            tags:
                - { name: kernel.event_subscriber }
    

Gotchas and Tips

Pitfalls

  1. Deprecation Warning The bundle is deprecated in favor of c975L/SiteBundle. Migrate to the newer bundle for long-term support.

  2. Twig Auto-Reloading Edits to Twig templates via the UI do not trigger Laravel’s template cache. Clear manually:

    php artisan view:clear
    
  3. File Permissions Ensure var/pageedit_archive/ is writable by the web server:

    mkdir -p var/pageedit_archive
    chmod -R 775 var/pageedit_archive
    
  4. TinyMCE Conflicts If TinyMCE fails to load, check for duplicate jQuery/Bootstrap includes. Use the bundle’s published assets exclusively.

  5. PDF Generation Limits PDF generation relies on external tools (e.g., wkhtmltopdf). Ensure dependencies are installed:

    sudo apt-get install wkhtmltopdf  # Debian/Ubuntu
    
  6. Protected Templates Templates in templates/protected/ cannot be edited via the UI, but they must still exist in the filesystem. Missing files will break the app.

Debugging

  • Log Archive Issues Enable debug mode to log archive operations:

    // config/packages/c975l_pageedit.yaml
    archive:
        debug: true
    
  • Check Route Conflicts Verify _pageedit routes don’t clash with existing routes. Use:

    php artisan route:list | grep pageedit
    
  • Twig Syntax Errors Validate Twig templates for syntax errors before editing via the UI. Use:

    php artisan twig:lint resources/views/
    

Extension Points

  1. Custom Archive Storage Override the archive service to use a database or cloud storage:

    // config/services.yaml
    services:
        C975L\PageEditBundle\Service\ArchiveService:
            arguments:
                $storage: '@custom.archive.storage'
    
  2. Dynamic Editable Regions Use Twig functions to conditionally enable editing:

    {% if app.user.isAdmin %}
        {% block editable %}
            {{ block.content|default('Admin-only content') }}
        {% endblock %}
    {% endif %}
    
  3. SEO Metadata Extend the sitemap with custom metadata:

    $sitemap->addUrl('/blog/post', [
        'changefreq' => 'monthly',
        'priority' => 0.7,
        'lastmod' => '2023-10-01',
        'images' => ['/images/post-thumbnail.jpg'],
    ]);
    
  4. Multi-Language Support Use the bundle’s pageedit.translation service to manage translations:

    $translations = $this->get('pageedit.translation');
    $translations->set('path/to/page', 'en', 'English content');
    $translations->set('path/to/page', 'fr', 'Contenu français');
    
  5. Custom Validation Add validation rules for editable content via a subscriber:

    public function onPageSave(PageEditEvent $event)
    {
        $content = $event->getContent();
        if (strpos($content, 'malicious') !== false) {
            throw new \RuntimeException('Invalid content detected.');
        }
    }
    
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