Documentation and tips
First of all, here are some publications concerning the extension migration from J3 to J4:
docs.joomla.org/Planning_for_Mini-Migrat...mla_3.10.x_to_4.x/en
docs.joomla.org/Potential_backward_compa...ssues_in_Joomla_4/en
docs.joomla.org/Potential_backward_compa...y_issues_in_Joomla_4
developer.joomla.org/news/764-joomla-3-10-and-joomla-4-0.html
JApplication
isAdmin () deprecated 4.0 Use isClient ('administrator') instead.
Replace
JFactory :: getApplication () -> isAdmin ()
by
JFactory :: getApplication () -> isClient ('administrator')
JError
To replace
JError :: raiseWarning ('',
through
JFactory :: getApplication () -> enqueueMessage (
and add 'WARNING' as the last parameter.
JDispatcher
Deprecated class placeholder. You should use JEventDispatcher instead
The CMS 'Event classes will be replaced with the `joomla / event` package
Currently (example):
$ dispatcher = JDispatcher :: getInstance ();
$ result = $ dispatcher-> trigger ('onContentBeforeSave', array ($ this -> _ context, & $ table, $ isNew, $ data));
Remove
$ dispatcher = JDispatcher :: getInstance ();
replace
$ result = $ dispatcher-> trigger ('onContentBeforeSave', array ($ this -> _ context, & $ table, $ isNew, $ data));
by
$ result = Factory :: getApplication () -> triggerEvent ('onContentBeforeSave', array ($ this -> _ context, & $ table, $ isNew, $ data));
JRegistry
JRegistry :: getInstance: if the object is to pass the information from the model to the view, retrieve the information in another way (getItem and getState for example)
JViewLegacy
Replace
$ this-> assign ('P1', $ P2)
and
$ this-> assignRef ('P1', $ P2)
by:
JDataBase
To replace :
if (! $ db-> query ()) {
Factory :: getApplication () -> enqueueMessage ($ db-> getErrorMsg (), 'ERROR');
return false;
}
through
try {
$ db-> execute ();
} catch (Exception $ e) {
Factory :: getApplication () -> enqueueMessage (JText :: sprintf ('JLIB_DATABASE_ERROR_FUNCTION_FAILED', $ e-> getCode (), $ e-> getMessage ()), 'ERROR');
return false;
}
Idem it is necessary to replace the $ db-> getErrorNum () and the $ db-> getErrorMsg () by an exception handling as above.
For example, replace:
$ db-> setQuery ($ query);
$ results = $ db-> loadObjectList ();
if ($ db-> getErrorNum ()) {
JFactory :: getApplication () -> enqueueMessage ($ db-> getErrorMsg (), 'WARNING');
return false;
}
through
$ db-> setQuery ($ query);
try {
$ results = $ db-> loadObjectList ();
} catch (Exception $ e) {
JFactory :: getApplication () -> enqueueMessage (JText :: sprintf ('JLIB_DATABASE_ERROR_FUNCTION_FAILED', $ e-> getCode (), $ e-> getMessage ()), 'ERROR');
return false;
}
JHtml
replace JHtml :: _ ('behavior.formvalidation');
by JHtml :: _ ('behavior.formvalidator');
JHtml :: _ ('behavior.tooltip'); // no longer exists
JForm
Use renderField () instead of getControlGroup
Use renderFieldset () instead of getControlGroups
Example :
Look for: form-> getControlGroup (
and replace with form-> renderField (
To install
Replace $ parent-> get ('manifest') -> version
by $ parent-> getManifest () -> version