devjoghurt/hof-plexexport-bundle
Installation Add the bundle via Composer:
composer require devjoghurt/hof-plexexport-bundle:dev-master
Register the bundle in app/AppKernel.php:
new Hof\PlexExportBundle\HofPlexExportBundle(),
Basic Configuration
Add minimal config in app/config/config.yml (optional if defaults suffice):
hof_plex_export:
config:
plex_url: "http://your-plex-server:32400"
data_dir: "%kernel.root_dir%/../web/data/plex"
First Use Case Render Plex media in a Twig template:
{{ plex_export() }}
Verify the output displays your Plex library (movies/shows) with thumbnails.
Dynamic Export Rendering
Use the plex_export() Twig function to display media in any template:
{% for item in plex_export() %}
<h2>{{ item.title }}</h2>
<img src="{{ item.thumbnail }}" />
{% endfor %}
Custom Templates Override the default template by passing a custom path:
{{ plex_export("AppBundle:Media:custom_plex.html.twig") }}
Configuration Overrides Pass runtime options to modify behavior:
{{ plex_export("AppBundle:Media:plex.html.twig", {
"sections": ["movies", "shows"],
"thumbnail_width": 300
}) }}
Integration with Symfony Forms Use the bundle to populate forms or grids with Plex metadata:
$plexData = $this->get('hof_plex_export.plex_export')->getData();
foreach ($plexData as $item) {
$form->add('media_item', EntityType::class, [
'class' => 'App\Entity\Media',
'choices' => [$item->id => $item->title],
]);
}
Scheduled Exports Trigger exports via a Symfony command (extend the bundle or create a custom one):
// src/Command/ExportPlexCommand.php
class ExportPlexCommand extends Command {
protected function execute(InputInterface $input, OutputInterface $output) {
$export = $this->getContainer()->get('hof_plex_export.plex_export');
$export->export(); // Hypothetical method (check bundle for actual API)
}
}
Plex Server Authentication
PlexExport service to include headers:
hof_plex_export:
config:
plex_url: "http://user:pass@your-plex-server:32400"
Hof\PlexExportBundle\Service\PlexExport class to add custom auth logic.File Permissions
data_dir is writable by the web server:
chmod -R 755 %kernel.root_dir%/../web/data/plex
Thumbnail Generation
thumbnail_width/height or disable thumbnails:
thumbnail_width: 0 # Disables thumbnails
Section Filtering
sections config accepts "all" or an array of section names (e.g., ["movies", "shows"]). Verify your Plex library’s section names match exactly.Caching Issues
getData() method.Check Plex API Response
$client = $this->get('hof_plex_export.plex_export')->getClient();
$response = $client->request('GET', '/library/sections');
var_dump($response->getContent());
Log Export Errors
PlexExport service:
$this->logger->error('Plex export failed', ['error' => $e->getMessage()]);
Validate Config
data_dir and plex_url are correct:
# app/config/validation.yml
services:
hof_plex_export.validator:
class: Symfony\Component\Validator\Validator\ValidatorInterface
arguments: [@validator]
calls:
- [validate, [%hof_plex_export.config%]]
Custom Exporters
// src/Hof/PlexExportBundle/Service/CustomPlexExport.php
class CustomPlexExport extends PlexExport {
public function getGenres() {
// Custom logic to fetch genres
}
}
services.yml:
services:
hof_plex_export.custom_export:
class: App\Service\CustomPlexExport
arguments: [%hof_plex_export.config%]
tags: [hof_plex_export.exporter]
Twig Extensions
// src/Twig/PlexExtension.php
class PlexExtension extends \Twig_Extension {
public function getFilters() {
return [
new \Twig_SimpleFilter('plex_duration', [$this, 'formatDuration']),
];
}
}
services.yml:
services:
app.twig.plex_extension:
class: App\Twig\PlexExtension
tags: [twig.extension]
Event Listeners
// src/EventListener/PlexExportListener.php
class PlexExportListener {
public function onPlexExport(ExportEvent $event) {
$event->setData($this->modifyData($event->getData()));
}
}
services.yml:
services:
app.plex_export_listener:
class: App\EventListener\PlexExportListener
tags:
- { name: kernel.event_listener, event: hof_plex_export.export, method: onPlexExport }
How can I help you explore Laravel packages today?