Joomla 3.x -> 4.x Migration Guide for Extensions

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.
Post Reply
gsexton
Joomla! Apprentice
Joomla! Apprentice
Posts: 19
Joined: Thu Mar 10, 2016 8:03 pm

Joomla 3.x -> 4.x Migration Guide for Extensions

Post by gsexton » Wed Sep 06, 2023 1:06 am

Can someone point me to a migration guide for Joomla extensions from 3.x -> 4.x?

I'm getting this error:

Call to undefined method Joomla\CMS\Document\HtmlDocument::addStyleSheetVersion()

I've read this page:

https://docs.joomla.org/Potential_backw ... oomla_4/en

and I'm not seeing anything that looks related. Is there an upgrade or migration guide targeted for extension developers?
Last edited by toivo on Wed Sep 06, 2023 4:22 am, edited 1 time in total.
Reason: mod note: moved from 4.x Extensions

User avatar
toivo
Joomla! Master
Joomla! Master
Posts: 16907
Joined: Thu Feb 15, 2007 5:48 am
Location: Sydney, Australia

Re: Joomla 3.x -> 4.x Migration Guide for Extensions

Post by toivo » Wed Sep 06, 2023 2:29 am

The function addStyleSheetVersion() is a Joomla 3 function that is part of the class Document, defined in the file libraries/src/Document/Document.php. That function does not exist in Joomla 4.

Which front end template is this website using? Are all the third party extensions compatible with Joomla 4?

Set 'Error Reporting' in the Global Configuration to 'Maximum' and turn on the Debug System option in the System tab and the error message and the PHP call stack will identify the script and the line number, where the error message comes from. Post the details here for advice.
Toivo Talikka, Global Moderator

User avatar
toivo
Joomla! Master
Joomla! Master
Posts: 16907
Joined: Thu Feb 15, 2007 5:48 am
Location: Sydney, Australia

Re: Joomla 3.x -> 4.x Migration Guide for Extensions

Post by toivo » Wed Sep 06, 2023 4:07 am

Sorry, if you are about to convert an extension to Joomla 4, you probably know all about the above! The documentation block of the function addStyleSheetVersion() in Joomla 3.10.12 gives this advice, which is inaccurate, because the function was not just deprecated but actually removed in Joomla 4:

Code: Select all

	 * @deprecated 4.0  This method is deprecated, use addStyleSheet(url, options, attributes) instead.
The function addStyleSheet() is defined in libraries/src/Document/Document.php:

Code: Select all

    /**
     * Adds a linked stylesheet to the page
     *
     * @param   string  $url      URL to the linked style sheet
     * @param   array   $options  Array of options. Example: array('version' => 'auto', 'conditional' => 'lt IE 9', 'preload' => array('preload'))
     * @param   array   $attribs  Array of attributes. Example: array('id' => 'stylesheet', 'data-test' => 1)
     *
     * @return  Document instance of $this to allow chaining
     *
     * @since   1.7.0
     *
     * @deprecated  4.3 will be removed in 6.0
     *              Use WebAssetManager
     *              Example: $wa->registerAndUseStyle(...);
     */
    public function addStyleSheet($url, $options = [], $attribs = [])
    {
An example of the function call can be found in the function stylesheet() in libraries/src/HTML/HTMLHelper.php.

If you prefer the latest, non-deprecated method, use the WebAssetManager, mentioned in the documentation block above: J4.x: Web Assets - Methods to Work with Styles
Toivo Talikka, Global Moderator

robbiej
Joomla! Apprentice
Joomla! Apprentice
Posts: 29
Joined: Wed Apr 06, 2016 11:22 am

Re: Joomla 3.x -> 4.x Migration Guide for Extensions

Post by robbiej » Wed Sep 27, 2023 6:58 pm

For components there's a step in the Joomla 3 MVC Tutorial at Upgrading to Joomla 4


Post Reply

Return to “Joomla! 4.x Coding”