Add a UDT on installation of a new module

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
chunteler
Forum Members
Forum Members
Posts: 14
Joined: Wed Oct 07, 2015 9:54 am

Add a UDT on installation of a new module

Post 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.
User avatar
Jo Morg
Dev Team Member
Dev Team Member
Posts: 1922
Joined: Mon Jan 29, 2007 4:47 pm

Re: Add a UDT on installation of a new module

Post 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);
}

 
"There are 10 types of people in this world, those who understand binary... and those who don't."
* by the way: English is NOT my native language (sorry for any mistakes...).
Code of Condut | CMSMS Docs | Help Support CMSMS
My developer Page on the Forge
GeekMoot 2015 in Ghent, Belgium: I was there!
GeekMoot 2016 in Leicester, UK: I was there!
DevMoot 2023 in Cynwyd, Wales: I was there!
chunteler
Forum Members
Forum Members
Posts: 14
Joined: Wed Oct 07, 2015 9:54 am

Re: Add a UDT on installation of a new module

Post by chunteler »

Great! Thanks.
User avatar
Jo Morg
Dev Team Member
Dev Team Member
Posts: 1922
Joined: Mon Jan 29, 2007 4:47 pm

Re: Add a UDT on installation of a new module

Post 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);
}

 
"There are 10 types of people in this world, those who understand binary... and those who don't."
* by the way: English is NOT my native language (sorry for any mistakes...).
Code of Condut | CMSMS Docs | Help Support CMSMS
My developer Page on the Forge
GeekMoot 2015 in Ghent, Belgium: I was there!
GeekMoot 2016 in Leicester, UK: I was there!
DevMoot 2023 in Cynwyd, Wales: I was there!
chunteler
Forum Members
Forum Members
Posts: 14
Joined: Wed Oct 07, 2015 9:54 am

Re: Add a UDT on installation of a new module

Post 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?
chunteler
Forum Members
Forum Members
Posts: 14
Joined: Wed Oct 07, 2015 9:54 am

Re: Add a UDT on installation of a new module

Post 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.
Post Reply

Return to “Developers Discussion”