Upgrade your extension from Joomla 3.9 to Joomla 4

More
1 month 2 days ago - 4 weeks 2 days ago #2169 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
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:
$ this-> P1 = $ P2;

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
Last edit: 4 weeks 2 days ago by Support Team.

Please Log in to join the conversation.

More
4 weeks 2 days ago - 4 weeks 2 days ago #2170 by Support Team
Some other tips:

error:

Call to undefined method Joomla\CMS\Filesystem\File::read()

change
JFile::read
into
jimport
or
file_get_contents


Class 'JRequest' not found
quote( JRequest::getVar('id') ));
into
quote( JFactory::getApplication()->input->post->get('id')));

or
$limitstart	= JRequest::getVar('limitstart', 0, '', 'int');
into

$limitstart = $this->input->get('limitstart', 0, 'int');




error:

500 behavior::framework not found.
JHtml::_('behavior.framework', true);
into
JHtml::_('jquery.framework', true);


or some other example
JHtml::_('behavior.modal');
into
JHtml::_('bootstrap.modal');
Last edit: 4 weeks 2 days ago by Support Team.

Please Log in to join the conversation.

Time to create page: 0.170 seconds
Events Joomla
MarvikShop
Finnaly it's here:
 
No bridges, no look a likes!
This is the ultimate integration
between Oscommerce and Joomla!
Documentation
Site Showcase
Follow us