Injecting JavaScript into admin list view

19 views
Skip to first unread message

Steven Berkson

unread,
Jan 19, 2025, 2:20:37 AMJan 19
to joomla-de...@googlegroups.com

Hi Folks,

 

I have a custom plugin working on the admin side that executes some actions on user management. I had to use a template override of the users list view to accomplish the task. I could make the entire plugin self-contained if I could properly inject a JavaScript file into the admin list view page, but there does not seem to be any early event like onContentPrepare to do that. Is there any way to inject JavaScript into admin views from a plugin?

Hannes Papenberg

unread,
Jan 19, 2025, 3:47:42 AMJan 19
to joomla-de...@googlegroups.com

You can check for the list view URL in onAfterRoute and then add the script. Alternatively on onBeforeCompileHead.


Steven Berkson <sber...@blazingimages.com> schrieb am So., 19. Jan. 2025, 08:20:

Hi Folks,

 

I have a custom plugin working on the admin side that executes some actions on user management. I had to use a template override of the users list view to accomplish the task. I could make the entire plugin self-contained if I could properly inject a JavaScript file into the admin list view page, but there does not seem to be any early event like onContentPrepare to do that. Is there any way to inject JavaScript into admin views from a plugin?

--
You received this message because you are subscribed to the Google Groups "Joomla! General Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to joomla-dev-gene...@googlegroups.com.
To view this discussion, visit https://groups.google.com/d/msgid/joomla-dev-general/SJ2PR22MB4167CE49DE0396541D08B8F0CBE42%40SJ2PR22MB4167.namprd22.prod.outlook.com.

Steven Berkson

unread,
Jan 19, 2025, 11:48:49 AMJan 19
to joomla-de...@googlegroups.com
Thanks. I'll try that.

Steven Berkson


From: 'Hannes Papenberg' via Joomla! General Development <joomla-de...@googlegroups.com>
Sent: Sunday, January 19, 2025 2:47:12 AM
To: joomla-de...@googlegroups.com <joomla-de...@googlegroups.com>
Subject: Re: [jgen] Injecting JavaScript into admin list view
 

Maciek Wołpiuk

unread,
Jan 20, 2025, 2:00:36 AMJan 20
to joomla-de...@googlegroups.com
Hello

I was make some plugin to inject some js script in Admin Side,

This was I make to make it.

public static function getSubscribedEvents(): array
    {
        return ['onBeforeCompileHead' => 'onBeforeCompileHead'];
    }

public function onBeforeCompileHead()
    {
$app = Factory::getApplication();

if (!$app->isClient('administrator')) {
return;
}

if ($this->getApplication()->getDocument() instanceof HtmlDocument) {
$assetManager = $this->getApplication()->getDocument()->getWebAssetManager();
            $assetManager->registerAndUseScript(
                'plg.system.adminjs',
                'plg_system_adminjs/adminjs.js',
                [],
                ['defer' => true],
                ['jquery']
            );
};
}

Pozdr
Maciek


Nie zawiera wirusów.www.avast.com

Reply all
Reply to author
Forward
0 new messages