I am trying to programatically create content categories when a new user is created. I have the plugin working and it is creating the categories however the categories do not appear in some admin/editor drop downs unless I manually edit and save them. I assume I am missing a step in the creation process that maybe updates the associations or something. Would appreciate any insight. Thanks in advance and here is my code:
Code: Select all
public static function createCategory($userId, $catName, $catAlias, $parentId, $rules)
{
$category_data['id'] = 0;
$category_data['parent_id'] = $parentId;
$category_data['created_user_id'] = $userId;
$category_data['title'] = $catName;
$category_data['alias'] = $catAlias;
$category_data['extension'] = 'com_content';
$category_data['published'] = 1;
$category_data['language'] = '*';
$category_data['params'] = array('category_layout' => '', 'image' => '');
$category_data['metadata'] = array('author' => '', 'robots' => '');
$category_data['associations'] = array();
if(!is_null($rules)){
$category_data['rules'] = $rules;
}
$basePath = JPATH_ADMINISTRATOR . '/components/com_categories';
require_once $basePath . '/models/category.php';
$config = array('table_path' => $basePath . '/tables');
$category_model = new CategoriesModelCategory($config);
if (!$category_model->save($category_data)) {
$err_msg = $category_model->getError();
return false;
} else {
$id = $category_model->getItem()->id;
$category_model->checkin($id);
return $id;
}
}