How hugomyb/filament-media-action works
Project type and purpose
• This is a PHP package for the Laravel ecosystem, specifically an add-on for the Filament admin panel ("Filament Media Action").
• Its purpose is to provide a reusable “MediaAction” component that automatically renders different media types (video, audio, PDF, image) in a modal when used in Filament Forms, Tables or Infolists.
File structure
• Top-level:
• bin/ (build scripts)
• src/ (main PHP classes: ServiceProvider, Facade, core Action classes under Actions, Forms, Tables, Infolists, Concerns)
• resources/ (Blade views, CSS/JS assets, translation files)
• docs/ (images and usage examples)
• tests/ (PHPUnit/Pest tests, architecture tests)
• stubs/ (scaffold templates)
• config/build and deployment files: composer.json, package.json, postcss.config.cjs, tailwind.config.js
• Patterns and conventions:
• Laravel package (ServiceProvider, Facade, vendor:publish tags)
• Filament Actions integrated into three contexts: Forms, Tables, Infolists
• Separation of concerns: PHP logic in src/, presentation in resources/views and resources/js/css, translations in resources/lang
Extract architecture insights from the README
• The package registers itself via FilamentMediaActionServiceProvider
• Provides a fluent MediaAction API (->media(), ->autoplay(), ->preload(), ->extraModalFooterActions())
• Uses Blade modal view under resources/views/actions/media-modal-content.blade.php
• Relies on JS/CSS assets for client-side behavior (resources/js, resources/css)
a. Main components
1. Host Laravel Application (consumer)
2. Filament Admin Panel (core)
3. Filament Media Action Package
– ServiceProvider & Facade
– MediaAction PHP classes (Actions, Forms/Components, Tables/Actions, Infolists/Components)
– Concerns (shared logic e.g. HasMedia)
4. Blade View (modal template)
5. Front-end assets (JS, CSS, Tailwind config)
6. Translations (lang files)
7. External media sources (video hosts, storage URLs)
8. Testing (automated tests in tests/)
b. Relationships and interactions
• At boot, Laravel loads FilamentMediaActionServiceProvider → registers MediaAction into Filament’s Action registry
• Developer uses MediaAction::make() in Filament resource (Form/Table/Infolist) → PHP class builds action metadata (media URL, options)
• On UI: user clicks action button → JavaScript listens → opens Blade modal (media-modal-content)
• Blade view passes media URL to the appropriate HTML5 player or YouTube iframe based on detected type (via Concerns logic)
• Front-end CSS/JS assets handle styling and playback controls
• Translations supply modal labels per configured locale
c. Architectural patterns/design principles
• Service Provider pattern for package registration
• Facade pattern for user-friendly API (MediaAction facade)
• Separation of presentation (Blade + assets) and business logic (PHP classes under src/)
• Single Responsibility: each Action class handles one integration point (Forms, Tables, Infolists)
• Dependency injection via Laravel’s container when building actions
d. Key technologies/frameworks/libraries
• PHP 8+, Laravel ServiceProvider & Facade
• Filament Admin Panel Actions API
• Blade templating
• Tailwind CSS & PostCSS for styling
• Vanilla JS or possibly Alpine.js for modal control
• PHPUnit/Pest for testing
Important notes
• Integration points: Forms, Tables, Infolists
• Publishing hooks (vendor:publish for views/translations)
• Test suite as a separate validation component
• Critical flows (e.g., media type detection via Concerns → choice of HTML5 player vs. iframe)