Check if a component is installed ?

For Joomla! 1.5 Coding related discussions, please use: http://groups.google.com/group/joomla-dev-general
Forum rules
Please use the mailing list here: http://groups.google.com/group/joomla-dev-general rather than this forum.
Locked
duddy67
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 229
Joined: Sun Jul 12, 2009 12:04 pm

Check if a component is installed ?

Post by duddy67 » Tue Aug 25, 2009 1:42 pm

Hi,

I'd like to know how to check if a component is installed during
the install of my module.
If component is not installed, an error message is displayed and the module installation stop.
I grab this code:

Code: Select all

jimport('joomla.application.component.helper');

if(!JComponentHelper::isEnabled('com_somecomponent', true))
{
    JError::raiseError('SOME_ERROR', JText('Module requires the Some
Extension component'));
}
I tried to put it in the mod_mymodule.php file but the module has been installed
just the same and no error message has been displayed.
Where should I put this code, in the helper.php file ?

Thanks

User avatar
nailson_imgn
Joomla! Guru
Joomla! Guru
Posts: 727
Joined: Wed Apr 15, 2009 5:33 pm
Location: Fortaleza, CE - Brasil

Re: Check if a component is installed ?

Post by nailson_imgn » Wed Aug 26, 2009 1:58 pm

duddy67 wrote:Hi,

I'd like to know how to check if a component is installed during
the install of my module.
If component is not installed, an error message is displayed and the module installation stop.
I grab this code:

Code: Select all

jimport('joomla.application.component.helper');

if(!JComponentHelper::isEnabled('com_somecomponent', true))
{
    JError::raiseError('SOME_ERROR', JText('Module requires the Some
Extension component'));
}
I tried to put it in the mod_mymodule.php file but the module has been installed
just the same and no error message has been displayed.
Where should I put this code, in the helper.php file ?

Thanks
For what I know, only components can run scripts at time of installation. Your module code will only be executed when the module is about to be displayed in your site...

However, you can create a custom element so your module can check if your required components are installed and display warning messages to an admin trying to create it.

Hope it helps...
.
Nailson Oliveira
Técnico de Tecnologia da Informação - Desenvolvedor Joomla!
-----------------------------------------------------------------------------------------

grayz
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 128
Joined: Tue Dec 12, 2006 8:37 pm

Re: Check if a component is installed ?

Post by grayz » Sun Sep 23, 2012 8:47 pm

Very simple way to check if component is installed. Works in module.

Code: Select all

jimport( 'joomla.application.component.controller' );
// Check if component is installed
if ( !JComponentHelper::isEnabled( 'com_NAME', true) ) {
	echo 'This modules requires component com_NAME!';
	return;
}
If component is not installed an error will be raise. Just a workaround.

Code: Select all

// Ignore warnings because component may not be installed
$warnHandlers = JERROR::getErrorHandling( E_WARNING ); 
JERROR::setErrorHandling( E_WARNING, 'ignore' );

// Check if component is installed
if ( !JComponentHelper::isEnabled( 'com_NAME', true) ) {
	echo 'This modules requires component com_NAME!';
	return;
}

// Reset the warning handler(s)
foreach( $warnHandlers as $mode ) {
	JERROR::setErrorHandling( E_WARNING, $mode );
}
www.justPHP.net - HACKS for Hot Property, Custom 404 Error Pages, Templates for Joomla etc.
Developing: www.zerno.org.ua


Locked

Return to “Joomla! 1.5 Coding”