Upgrade your extension from Joomla 3.9 to Joomla 4

Meer
2 jaren 8 maanden geleden - 2 jaren 7 maanden geleden #2169 door 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
Code:
JFactory :: getApplication () -> isAdmin ()
by
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)
and
Code:
$ this-> assignRef ('P1', $ P2)
by:
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
Laatst bewerkt 2 jaren 7 maanden geleden doorSupport Team.

Graag Inloggen of een account aanmaken deelnemen aan het gesprek.

Meer
2 jaren 7 maanden geleden - 2 jaren 7 maanden geleden #2170 door Support Team
Some other tips:

error:

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

change
Code:
JFile::read
into
Code:
jimport
or
Code:
file_get_contents


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

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

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




error:

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


or some other example
Code:
JHtml::_('behavior.modal');
into
Code:
JHtml::_('bootstrap.modal');
Laatst bewerkt 2 jaren 7 maanden geleden doorSupport Team.

Graag Inloggen of een account aanmaken deelnemen aan het gesprek.

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