If you already override jomsocial template files then don't think that in same way you can override controller as well.
Before talking about how to override Jomsocial Controller, lets see why we need to override controller. If you hack the core files directly & made changes as you want. After some day when you upgrade jomsocial then those changes from the hacked files will be removed & then again you have to hack the core files. So this is very tedious task to check which file & what code you have hacked. Solution on hacking is obviously you have to override controller.
To override jomsocial controller you need a plugin which will override controller. In this plugin we just replace default controller object with our own custom class.
Before the system controller is created. Plugin may override the controller class name.
Plugin should contain following code.
<?php
defined( '_JEXEC' ) or die( 'Restricted access' );
jimport( 'joomla.plugin.plugin' );
require_once( JPATH_SITE .'/components/com_community/libraries/core.php');
require_once( JPATH_SITE .'/components/com_community/controllers/mybulletin.php');
class plgCommunityMybulletin extends CApplications
{
function plgCommunityMybulletin(& $subject, $config){
parent::__construct($subject, $config);
}
function onBeforeControllerCreate( &$controllerClassName )
{
$view = JRequest::getVar('view');
if($view == 'groups') {
$controllerClassName = 'MybulletinController'; // MybulletinController is class name which extends in your controller
return true;
}
return false;
}
}
Lets see the how to create controller.
If you wanna override groups controller then copy that file & paste it in the same folder(com_community/controller). Rename that file with what you have mentioned in plugin($controllerClassName value). In this case i rename that file with mybulletin.php & do changes as you want. Just make sure that you have added following line at the top of the file.
jimport ('joomla.application.component.controller');
require_once (COMMUNITY_COM_PATH.DS.'controllers'.DS.'controller.php');
To off email on bulletin creation i did override jomsocial group controller. You can find plugin & controller files here & make changes as you want.
I followed your example, and it worked perfectly. Thanks.
ReplyDeleteAmol,
ReplyDeleteI think
require_once (COMMUNITY_COM_PATH.DS.'controllers'.DS.'controller.php');
is sufficient, because it contains
jimport ('joomla.application.component.controller');
Yitwail Thanks for comment..
ReplyDeleteIf it works then no problem
First of all you owe a "Thanks". It helped me a lot when I was trying to override Register controller and also View in the same way.
ReplyDeleteJomSocial's official documentation site doesn't
have descriptive contents. :(
Please keep it up. Always share what you've learned. Many many thanks. :)
@sharifkamrul thank you for such a sweet comment & i always try to share what i learned..
DeleteAmazingly simple guide. On another note, have you changed the default user behaviour to allow multiple user types. Not the Multiple profiles JomSocial allows, but actually extend the user class to child classes ?
ReplyDeleteI know this if off topic but I'm looking into starting my own weblog and was wondering what all is required to get set up? I'm assuming having a blog like yours would cost a pretty penny?
ReplyDeleteI'm not very internet savvy so I'm not 100% certain. Any recommendations or advice would be greatly appreciated. Thank you
Here is my weblog; quick cash advance loans