Howto - upgrade addScript method

For Joomla! 4.x Coding related discussions, you could also use: http://groups.google.com/group/joomla-dev-general

Moderators: ooffick, General Support Moderators

Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
Forum Post Assistant - If you are serious about wanting help, you will use this tool to help you post.
Windows Defender SmartScreen Issues <-- please read this if using Windows 10.
Locked
User avatar
rbuelund
Joomla! Guru
Joomla! Guru
Posts: 846
Joined: Sat Feb 10, 2007 9:07 pm
Location: Århus
Contact:

Howto - upgrade addScript method

Post by rbuelund » Sun Dec 19, 2021 5:27 pm

How would I go about upgrading this piece of code (from my custom J3 component) to being ready for Joomla 4?

$document = Factory::getDocument();
$document->addScript(URI::root() . "administrator/components/com_mycomponent/views/datarow/submitbutton.js");

I believe the addScript method does not exist in the J!4 Factory class anymore?
Last edited by imanickam on Mon Dec 20, 2021 7:21 am, edited 1 time in total.
Reason: Moved topic » from Migrating and Upgrading to Joomla! 4.x to Joomla! 4.x Coding
Ronny Buelund
Coordinator of the Danish Joomla Translation Team: http://danskjoomla.dk
Owner of http://ableit.dk

User avatar
pmleconte
Joomla! Guru
Joomla! Guru
Posts: 591
Joined: Fri Mar 17, 2017 12:55 pm
Location: France

Re: Howto - upgrade addScript method

Post by pmleconte » Mon Dec 20, 2021 10:55 am

Hi,

addscript is still working in J4.

However, you could use J4 Web assets : https://docs.joomla.org/J4.x:Web_Assets

use, for example :
/** @var Joomla\CMS\WebAsset\WebAssetManager $wa */
$wa = Factory::getApplication()->getDocument()->getWebAssetManager();
$wa->registerAndUseScript('mybutton','administrator/components/com_mycomponent/views/datarow/submitbutton.js');

Pascal
If anything can go wrong, it will.
https://www.conseilgouz.com/en


Locked

Return to “Joomla! 4.x Coding”