If you need to load custom JS or CSS into the admin or editmode UI, you have two options.
Add OpenDxpBundleAdminClassicInterface
to your bundle class. Use BundleAdminClassicTrait
to implement the four required methods:
use OpenDxp\Extension\Bundle\AbstractOpenDxpBundle;
use OpenDxp\Extension\Bundle\OpenDxpBundleAdminClassicInterface;
use OpenDxp\Extension\Bundle\Traits\BundleAdminClassicTrait;
class MyBundle extends AbstractOpenDxpBundle implements OpenDxpBundleAdminClassicInterface
{
use BundleAdminClassicTrait;
public function getJsPaths(): array
{
return ['/bundles/mybundle/js/admin.js'];
}
public function getCssPaths(): array
{
return ['/bundles/mybundle/css/admin.css'];
}
}Use EncoreHelper
to resolve built file paths from entrypoints.json:
use OpenDxp\Helper\EncoreHelper;
public function getJsPaths(): array
{
return EncoreHelper::getBuildPathsFromEntrypoints(
$this->getPath() . '/public/build/mybundle/entrypoints.json'
);
}
public function getCssPaths(): array
{
return EncoreHelper::getBuildPathsFromEntrypoints(
$this->getPath() . '/public/build/mybundle/entrypoints.json',
'css'
);
}Subscribe to events from BundleManagerEvents:
<?php
namespace App\EventListener;
use OpenDxp\Event\BundleManager\PathsEvent;
use OpenDxp\Event\BundleManagerEvents;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class AdminAssetsListener implements EventSubscriberInterface
{
public static function getSubscribedEvents(): array
{
return [
BundleManagerEvents::JS_PATHS => 'onJsPaths',
BundleManagerEvents::CSS_PATHS => 'onCssPaths',
];
}
public function onJsPaths(PathsEvent $event): void
{
$event->addPaths(['/bundles/app/js/admin.js']);
}
public function onCssPaths(PathsEvent $event): void
{
$event->addPaths(['/bundles/app/css/admin.css']);
}
}Assets registered via either method are loaded last on OpenDXP startup, in registration order.
- Admin UI JavaScript — how to use the loaded JS to extend the UI
- BundleManagerEvents source