Weave 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

Bartacus Bundle Laravel Package

bartacus/bartacus-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation Add the bundle via Composer in your TYPO3 project:

    composer require bartacus/bartacus-bundle
    

    Register the bundle in composer.json under extra.bundles:

    "extra": {
        "bundles": [
            "Bartacus\\Bundle\\BartacusBundle\\BartacusBundle"
        ]
    }
    
  2. Basic Configuration Enable the bundle in config/packages/bartacus.yaml:

    bartacus:
        enabled: true
        dev_mode: '%kernel.debug%'
    
  3. First Use Case: Symfony Controller in TYPO3 Create a Symfony controller (e.g., src/Controller/MyController.php) and annotate it with #[ContentElement]:

    use Bartacus\Bundle\BartacusBundle\Annotation\ContentElement;
    
    #[ContentElement(
        type: 'my_custom_element',
        templatePath: 'EXT:my_extension/Resources/Private/Templates/MyTemplate.html.twig'
    )]
    class MyController extends AbstractController {
        public function myAction(): Response {
            return $this->render('my_template.html.twig', [
                'content' => 'Hello from Symfony!'
            ]);
        }
    }
    

    Register the controller as a service in services.yaml:

    services:
        App\Controller\MyController:
            tags: ['bartacus.make_instance']
    
  4. TypoScript Integration Add the content element to TypoScript:

    tt_content.my_custom_element {
        templateName = my_template
        templateRootPaths.0 = EXT:my_extension/Resources/Private/Templates/
    }
    

Implementation Patterns

Workflows

  1. Symfony Controller as Content Element

    • Use #[ContentElement] to bind Symfony controllers to TYPO3 content elements.
    • Leverage Symfony’s DI container for services (e.g., Doctrine, Twig, Forms).
    • Example:
      #[ContentElement(type: 'blog_post', templatePath: 'EXT:blog/Resources/Private/Templates/Post.html.twig')]
      class BlogPostController extends AbstractController {
          public function showAction(BlogPost $post): Response {
              return $this->render('Post.html.twig', ['post' => $post]);
          }
      }
      
  2. Request Handling

    • Route Detection: Symfony routes are resolved before TYPO3’s default routing. Configure routes in config/routes.yaml:
      app.my_route:
          path: /symfony/{id}
          controller: App\Controller\MyController::myAction
      
    • Locale Unification: Use _locale from Symfony requests in TYPO3 via bartacus.locale_resolver.
  3. Dependency Injection

    • Tag services with bartacus.make_instance to integrate them into TYPO3’s DI container.
    • Example:
      services:
          App\Service\MyService:
              tags: ['bartacus.make_instance']
      
  4. Caching

    • Override TYPO3’s caching for Symfony-rendered content elements:
      bartacus:
          cache:
              enabled: true
              ttl: 3600
      
  5. Error Handling

    • Symfony’s error handler replaces TYPO3’s in dev mode. Customize error pages in config/packages/twig.yaml:
      twig:
          exception_controller: App\Controller\ErrorController::showException
      

Integration Tips

  • Extbase Models: Auto-map Extbase models to Symfony entities by extending Bartacus\Bundle\BartacusBundle\DependencyInjection\Compiler\ExtbasePass.
  • Twig Integration: Use Symfony’s Twig for templating while keeping TYPO3’s Fluid for legacy templates.
  • Middleware: Reorder TYPO3’s middleware stack to prioritize Symfony routes:
    bartacus:
        middleware:
            order: ['symfony_router', 'typo3_redirect']
    

Gotchas and Tips

Pitfalls

  1. Route Conflicts

    • Symfony routes may conflict with TYPO3’s URL handling. Ensure routes are unique and use bartacus.route_priority to manage precedence:
      bartacus:
          route_priority: ['symfony', 'typo3']
      
  2. Caching Inconsistencies

    • Symfony’s cache (e.g., OPcache) may not invalidate TYPO3’s cache. Clear caches manually or use bartacus.cache.invalidate_on_write: true.
  3. Dev vs. Prod Mode

    • Symfony’s error handler only activates in dev mode. For production, configure TYPO3’s error handler separately:
      bartacus:
          dev_mode: '%kernel.debug%'
      
  4. Attribute Parsing

    • The #[ContentElement] attribute requires PHP 8+. For older versions, use XML/YAML annotations or upgrade.
  5. UpgradeWizard Compatibility

    • If using UpgradeWizardInterface, ensure the implementation is tagged as a service:
      services:
          App\UpgradeWizard\MyWizard:
              tags: ['bartacus.upgrade_wizard']
      

Debugging

  • Symfony vs. TYPO3 Logs: Check both var/log/symfony.log and TYPO3’s var/log/ for errors.
  • Route Debugging: Use Symfony’s debug:router command to inspect routes:
    php bin/console debug:router
    
  • DI Container Dumps: Dump services to verify integration:
    php bin/console debug:container | grep bartacus
    

Tips

  1. Custom Caching Extend Bartacus\Bundle\BartacusBundle\Cache\ContentElementCache to implement custom logic:

    class CustomCache extends ContentElementCache {
        protected function getKey(): string {
            return 'custom_' . parent::getKey();
        }
    }
    

    Register it in services.yaml:

    services:
        App\Cache\CustomCache:
            decorates: bartacus.cache.content_element
            arguments: ['@App\Cache\CustomCache.inner']
    
  2. TypoScript Overrides Override TypoScript for Symfony-rendered elements dynamically:

    use Bartacus\Bundle\BartacusBundle\Event\TypoScriptEvent;
    
    class TypoScriptSubscriber implements EventSubscriberInterface {
        public static function getSubscribedEvents(): array {
            return [TypoScriptEvent::PRE_PROCESS => 'onTypoScript'];
        }
    
        public function onTypoScript(TypoScriptEvent $event): void {
            $event->addTypoScript('tt_content.my_custom_element {
                someSetting = 123
            }');
        }
    }
    
  3. Performance Disable bartacus.cache.enabled in development to avoid stale content during testing.

  4. Testing Use Symfony’s WebTestCase for controller tests and TYPO3’s FunctionalTestCase for integration tests:

    class MyControllerTest extends WebTestCase {
        public function testMyAction() {
            $client = static::createClient();
            $client->request('GET', '/my-route');
            $this->assertResponseStatusCodeSuccess();
        }
    }
    
  5. Extension Points

    • Event Listeners: Subscribe to bartacus.events (e.g., ContentElementEvent, RequestEvent).
    • Compiler Passes: Extend DI compilation with Bartacus\Bundle\BartacusBundle\DependencyInjection\Compiler\* classes.
    • Twig Extensions: Add custom Twig functions/filters via bartacus.twig.extensions.
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.
htinlynn/genius-helper
maco-studios/hephaestus
elmogy/larafast
xeviant/laravel-paystack
gorilladash/laravel-website-sdk
martialbe/flysystem-oss
chondal/3312client
jeroen-g/flickr
opscale-co/nova-genbi
itsjustvita/laravel-retention
tequilarapido/trackit
gregsphotography/site-builder-filament
cabaoctavio/laravel-query-log
gregsphotography/site-builder-components
io-digital/clickatell
snowsoft/laravel-admin
oxygen/auth
relicsoftware/barakah-payment-gateway
tobya/work-with-composer
equipc/laravel-email-validator