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

Shortcuts Bundle Laravel Package

appventus/shortcuts-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation:

    composer require appventus/shortcuts-bundle:dev-master
    

    Add to AppKernel.php:

    new AppVentus\Awesome\ShortcutsBundle\AvAwesomeShortcutsBundle(),
    
  2. Twig Configuration (Symfony 2.x):

    # app/config/config.yml
    twig:
        form:
            resources:
                - 'AvAwesomeShortcutsBundle::fields.html.twig'
    

    For Symfony 3.x+:

    twig:
        form_themes:
            - 'AvAwesomeShortcutsBundle::fields.html.twig'
    
  3. Load Assets (in your base template):

    {% block stylesheets %}
        {{ parent() }}
        {{ asset('bundles/avawesomeshortcuts/css/datepicker.css') }}
    {% endblock %}
    
    {% block javascripts %}
        {{ parent() }}
        {{ asset('bundles/avawesomeshortcuts/js/bootstrap-datepicker.js') }}
    {% endblock %}
    

First Use Case

Inject the ShortcutService in a controller to leverage common utilities:

use AppVentus\Awesome\ShortcutsBundle\Service\ShortcutService;

class MyController extends Controller
{
    public function indexAction()
    {
        $shortcuts = $this->get('av.shortcuts');
        $shortcuts->congrat('Operation successful!'); // Flash success message
        return $this->render('...');
    }
}

Implementation Patterns

Common Workflows

  1. Flash Messages: Replace repetitive flash bag logic with shortcuts:

    $this->get('av.shortcuts')->congrat('Success!');
    $this->get('av.shortcuts')->scold('Error occurred!');
    
  2. Form Error Handling: Convert form errors to a readable string for AJAX responses:

    $formErrorService = $this->get('av.form_error_service');
    $errors = $formErrorService->getRecursiveReadableErrors($form);
    return new JsonResponse(['errors' => $errors]);
    
  3. Email Shortcuts: Send emails with minimal boilerplate:

    $shortcuts->createAndQueueMail(
        'user@example.com',
        'Welcome',
        'email_template.html.twig',
        ['name' => 'John']
    );
    
  4. Redactor Integration: Use the RedactorType for rich-text fields:

    $builder->add('content', RedactorType::class, [
        'options' => [
            'lang' => $this->getRequest()->getLocale(),
            'plugins' => ['video'],
            'buttons' => ['bold', 'italic', 'image', 'link'],
        ],
    ]);
    

Integration Tips

  • Extend AwesomeController (if available) to auto-inject ShortcutService:
    class MyController extends \AppVentus\Awesome\ShortcutsBundle\Controller\AwesomeController
    {
        public function indexAction()
        {
            $this->congrat('Shortcut method!'); // Direct access
        }
    }
    
  • Customize Alerts: Override AvAlertifyBundle templates in your theme to match your design system.
  • Session Management: Use getSession()/setSession() for app-wide state without reinventing logic.

Gotchas and Tips

Pitfalls

  1. Deprecated Bundle:

    • Last release in 2017; test thoroughly in your environment. May require Symfony 2.x adjustments for newer versions.
    • No dependents; ensure compatibility with your stack (e.g., Twig 1.x vs. 2.x).
  2. Asset Loading:

    • Hardcoded paths in datepicker.css/bootstrap-datepicker.js may need updates if using Symfony AssetMapper or Webpack Encore.
    • Fix: Override asset paths in your config.yml or use {% block %} in templates.
  3. Redactor Configuration:

    • imageUpload path (/bundles/avawesomeshortcuts/...) is absolute and may break in subdirectories.
    • Fix: Use asset() or configure a route for uploads:
      # config/routes.yml
      av_awesome_shortcuts_image_upload:
          path: /upload/image
          defaults: { _controller: AvAwesomeShortcutsBundle:Default:imageUpload }
      
  4. Service Naming:

    • Service IDs (av.shortcuts, av.form_error_service) are case-sensitive. Double-check autowiring if using Symfony 4+.

Debugging Tips

  • Flash Messages Not Showing? Ensure AvAlertifyBundle is installed and configured. Check if the bundle is enabled in AppKernel.php.
  • Form Errors Empty? Verify getRecursiveReadableErrors() is called after $form->submit() and validation.
  • Redactor Not Loading? Check browser console for 404s on JS/CSS. Validate assetic_injector.json is processed (Symfony 2.x only).

Extension Points

  1. Add Custom Shortcuts: Extend ShortcutService and override methods:

    class CustomShortcutService extends \AppVentus\Awesome\ShortcutsBundle\Service\ShortcutService
    {
        public function customMethod($param)
        {
            // Logic here
        }
    }
    

    Register as a service:

    services:
        av.shortcuts:
            class: App\Service\CustomShortcutService
            parent: av.shortcuts.base
    
  2. Modify Alert Templates: Override AvAlertifyBundle templates in app/Resources/AvAlertifyBundle/views/ to customize layouts.

  3. Session Handling: Extend setSession()/getSession() to add app-specific logic (e.g., encryption, TTL).

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.
emuniq/filament-browser-notifications
syriable/filament-translator
hungnm28/livewire-form
wenprise/eloquent
crudly/encrypted
fadion/bouncy
cuci/prototurk-sdk
gos/pubsub-router-bundle
cuci/prototurk-sdk-symfony
clementtalleu/easyadmin-markdown-bundle
codeflextech/permission-manager
karnoweb/livewire-datepicker
sayedenam/sayed-dashboard
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui