And it works more or less as expected. But does not generate an alias or URL on creation based on the instance template for alias and URLs.
I've tried to use GenerateAlias() and GenerateSlug() and i do at least get the item_id inserted in the alias field, but nothing else. URL field is still empty.
My full UDT:
Code: Select all
/**
* Load wanted ListItExtended instance, where you wan't to save items.
* If instance can't be loaded, it will silently return.
*/
$mod = cmsms()->GetModuleInstance('LISELessons');
if(!is_object($mod))
return;
/**
* Intitate item with identifier 'alias', $params['title'] comes from FormBuilder.
* Do duplication check with 'item_id', silently return, if item already in database.
*/
$alias = munge_string_to_url($params['title'], true);
$obj = $mod->LoadItemByIdentifier('alias', $alias);
if($obj->item_id > 0)
return;
/**
* Fill previously initiated ListIt2Item object with values from form submission.
* NOTICE: All params that are not known by ListIt2Item object are going to ignored.
*/
$obj->title = $params['title'];
$obj->alias = $mod->GenerateAlias($obj->title, 'LISELessons');
$obj->slug = $mod->GenerateSlug('LISELessons');
foreach($params as $key => $value) {
if(isset($obj->fielddefs[$key])){
if($value != "[unspecified]"){
$obj->$key = $value;
}
}
}
/**
* Save this object to database by using ListItExtended API.
*/
$mod->SaveItem($obj);