A set of notes and code examples, mostly for myself, illustrating some of the changes necessary to make a component Joomla 4 compatible. You will probably need to update the database tables for your component as well.
$editor = Editor::getInstance(JFactory::getConfig()->get('editor'));
$editor->getContent($this->elementId);
Replace with javascript
Joomla.editors.instances[‘ . $this->elementId . '].getValue()
More information can be found in
media/system/js/core.js:17
$dispatcher = JEventDispatcher::getInstance();
$result = $dispatcher->trigger($this->event_before_save , array($eventDataBeforeSave));
Replace with
use Joomla\CMS\Factory ;
$result = Factory::getApplication()->triggerEvent($this->event_before_save , array($eventDataBeforeSave));
JHtml::_('behavior.formvalidation');
JHtml::_('behavior.keepalive ’);
Replace with
/** @var Joomla\CMS\WebAsset\WebAssetManager $wa */
$wa = $this->document->getWebAssetManager();
$wa->useScript('keepalive')
->useScript('form.validate ’);
JHtml::_('behavior.tooltip ’);
Replace with
JHtml::_('bootstrap.tooltip ’);
$this->alias = JApplicationHelper::stringURLSafe($this->alias );
Replace with
use Joomla\CMS\Filter\OutputFilter;
$this->alias = OutputFilter::stringURLSafe($this -> alias);
Remove or comment out all
$this->sidebar = JHtmlSidebar::render();
Remove or comment out
JHtml::_('formbehavior.chosen', 'select’);
You may need to add the following to the form xml
class ="custom-select ”
You can’t add the route helper like this
require_once ( JPATH_SITE . DIRECTORY_SEPARATOR . 'components' . DIRECTORY_SEPARATOR . 'com_content' . DIRECTORY_SEPARATOR . 'helpers' . DIRECTORY_SEPARATOR . 'route.php ’ );
A quick fix is to use this instead
require_once ( JPATH_SITE . DIRECTORY_SEPARATOR . 'components' . DIRECTORY_SEPARATOR . 'com_content' . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'Helper' . DIRECTORY_SEPARATOR . 'RouteHelper.php ’ );
JArrayHelper::toInteger($ids);
Replace with
use Joomla\Utilities\ArrayHelper;
ArrayHelper::toInteger($ids);