Page 1 of 1
Add a UDT on installation of a new module
Posted: Wed Oct 07, 2015 9:59 am
by chunteler
Hi,
I'm using CMSMS 1.12.
I'm busy developing a module for a customer.
Is it possible to have a UDT created on installation of a module? How?
Thanks.
Re: Add a UDT on installation of a new module
Posted: Wed Oct 07, 2015 11:29 am
by Jo Morg
There are a few API methods to do that:
http://apidoc.cmsmadesimple.org/classes ... tions.html
Just use them on your install method.
Untested, but should be something like this:
Code: Select all
$usertagops = cmsms()->GetUserTagOperations();
$tagname = 'foo';
$tagtext = '/* some tag code */';
if( !$usertagops::UserTagExists($tagname) )
{
$usertagops::SetUserTag($tagname, $tagtext);
}
Re: Add a UDT on installation of a new module
Posted: Wed Oct 07, 2015 12:27 pm
by chunteler
Great! Thanks.
Re: Add a UDT on installation of a new module
Posted: Wed Oct 07, 2015 4:45 pm
by Jo Morg
Just notice I made a mistake, called the methods statically on a non static context, sorry correction follows:
Code: Select all
$usertagops = cmsms()->GetUserTagOperations();
$tagname = 'foo';
$tagtext = '/* some tag code */';
if( !$usertagops->UserTagExists($tagname) )
{
$usertagops->SetUserTag($tagname, $tagtext);
}
Re: Add a UDT on installation of a new module
Posted: Tue Oct 13, 2015 11:02 am
by chunteler
Yes, I had already corrected that.
Another question: I have quite some PHP code to set inside the $tagtext variable with single en double quotes. How can I best add my code?
Re: Add a UDT on installation of a new module
Posted: Tue Oct 13, 2015 12:30 pm
by chunteler
Ok. Forget my last reply. I figured it out.
Another question:
Which code can I use to make sure the UDT is removed when the module in uninstalled.