Calling code from other modules

Talk about writing modules and plugins for CMS Made Simple, or about specific core functionality. This board is for PHP programmers that are contributing to CMSMS not for site developers
Post Reply
rmelberg

Calling code from other modules

Post by rmelberg »

I am working on integrating the Form Builder and Newsletters Made Simple modules.  What I want is a single form which collects a bunch of data and then signs the user up for a newsletter (if requested, of course).  I thought I could call one of the actions in the NMS from a User Defined Tag, but I don't know how to call another module's code.  Is there an easy way to do this?  The NMS has a do_create_new_user action, and if I add the correct params, I think it would just work.

Thanks,
Rorik
User avatar
aln_cms
Forum Members
Forum Members
Posts: 88
Joined: Mon Jan 08, 2007 7:09 pm
Location: Ireland

Re: Calling code from other modules

Post by aln_cms »

Hi,
This isn't my development system, so I don't have access to my code but here goes :

Code: Select all



$modulename = 'FormBuilder';

$cmsmodules = &$gCms->modules;
if (isset($cmsmodules[$modulename]))
{
if (isset($cmsmodules[$modulename]['object'])
	&& $cmsmodules[$modulename]['installed'] == true
	&& $cmsmodules[$modulename]['active'] == true ) {

$result = $cmsmodules[$modulename]['object']->YourFunctionCallHere();

}


This is rough, but it should gt you near.
--
Alan Ryan
Lead Developer
CodeCrunchers Internet Software Development - Ireland
http://www.codecrunchers.ie
rmelberg

Re: Calling code from other modules

Post by rmelberg »

Thanks, I will give it a shot.

-R
rmelberg

Re: Calling code from other modules

Post by rmelberg »

Just for posterity, the code that ended up working in the User Defined Tag was this, very similar to what was suggested, but with a couple of wrinkles, like having to define the global $gCms var and such.  Thanks for your help aln_cms!

//AddUsertoEmailList
//Adds user to Newsletter email list

$email = $params['Email'];
$params['email'] = $email;

$name = $params['Name'];
$params['username'] = $name;

$lists = array(1);
$params['lists'] = $lists;

$modulename = 'NMS';

global $gCms;

$cmsmodules = $gCms->modules;

if (isset($cmsmodules[$modulename]))
{
    $returnid = 0;
    $cmsmodules[$modulename]['object']->DoAction('do_create_new_user','',$params,$returnid);
}
User avatar
aln_cms
Forum Members
Forum Members
Posts: 88
Joined: Mon Jan 08, 2007 7:09 pm
Location: Ireland

Re: Calling code from other modules

Post by aln_cms »

my pleasure.
--
Alan Ryan
Lead Developer
CodeCrunchers Internet Software Development - Ireland
http://www.codecrunchers.ie
sn3p
Forum Members
Forum Members
Posts: 169
Joined: Mon Oct 15, 2007 2:27 pm

Re: Calling code from other modules

Post by sn3p »

I've also made an UDT for this, check it out here.
Post Reply

Return to “Developers Discussion”