- Posts: 106
- Thank you received: 10
Upgrade your extension from Joomla 3.9 to Joomla 4
- Support Team
- Topic Author
- Offline
- Moderator
Less
More
3 years 3 months ago - 3 years 3 months ago #2169
by Support Team
Upgrade your extension from Joomla 3.9 to Joomla 4 was created by Support Team
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
by
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):
Remove
replace
by
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
and
by:
JDataBase
To replace :
through
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
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
Code:
JFactory :: getApplication () -> isAdmin ()
Code:
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):
Code:
$ dispatcher = JDispatcher :: getInstance ();
$ result = $ dispatcher-> trigger ('onContentBeforeSave', array ($ this -> _ context, & $ table, $ isNew, $ data));
Remove
Code:
$ dispatcher = JDispatcher :: getInstance ();
replace
Code:
$ result = $ dispatcher-> trigger ('onContentBeforeSave', array ($ this -> _ context, & $ table, $ isNew, $ data));
by
Code:
$ 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
Code:
$ this-> assign ('P1', $ P2)
Code:
$ this-> assignRef ('P1', $ P2)
Code:
$ this-> P1 = $ P2;
JDataBase
To replace :
Code:
if (! $ db-> query ()) {
Factory :: getApplication () -> enqueueMessage ($ db-> getErrorMsg (), 'ERROR');
return false;
}
through
Code:
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
Last edit: 3 years 3 months ago by Support Team.
Please Log in or Create an account to join the conversation.
- Support Team
- Topic Author
- Offline
- Moderator
Less
More
- Posts: 106
- Thank you received: 10
3 years 3 months ago - 3 years 3 months ago #2170
by Support Team
Replied by Support Team on topic Upgrade your extension from Joomla 3.9 to Joomla 4
Some other tips:
error:
Call to undefined method Joomla\CMS\Filesystem\File::read()
change
into
or
Class 'JRequest' not found
into
or
into
error:
500 behavior::framework not found.
into
or some other example
into
error:
Call to undefined method Joomla\CMS\Filesystem\File::read()
change
Code:
JFile::read
Code:
jimport
Code:
file_get_contents
Class 'JRequest' not found
Code:
quote( JRequest::getVar('id') ));
Code:
quote( JFactory::getApplication()->input->post->get('id')));
or
Code:
$limitstart = JRequest::getVar('limitstart', 0, '', 'int');
$limitstart = $this->input->get('limitstart', 0, 'int');
error:
500 behavior::framework not found.
Code:
JHtml::_('behavior.framework', true);
Code:
JHtml::_('jquery.framework', true);
or some other example
Code:
JHtml::_('behavior.modal');
Code:
JHtml::_('bootstrap.modal');
Last edit: 3 years 3 months ago by Support Team.
Please Log in or Create an account to join the conversation.