Adds/edits/deletes aggregator categories.
$edit: An associative array describing the category to be added/edited/deleted.
function aggregator_save_category($edit) {
$link_path = 'aggregator/categories/';
if (!empty($edit['cid'])) {
$link_path .= $edit['cid'];
if (!empty($edit['title'])) {
db_merge('aggregator_category')
->key(array(
'cid' => $edit['cid'],
))
->fields(array(
'title' => $edit['title'],
'description' => $edit['description'],
))
->execute();
$op = 'update';
}
else {
db_delete('aggregator_category')
->condition('cid', $edit['cid'])
->execute();
// Make sure there is no active block for this category.
if (module_exists('block')) {
foreach (entity_load_multiple_by_properties('block', array(
'plugin' => 'aggregator_category_block:' . $edit['cid'],
)) as $block) {
$block
->delete();
}
}
$edit['title'] = '';
$op = 'delete';
}
}
elseif (!empty($edit['title'])) {
// A single unique id for bundles and feeds, to use in blocks.
$link_path .= db_insert('aggregator_category')
->fields(array(
'title' => $edit['title'],
'description' => $edit['description'],
'block' => 5,
))
->execute();
$op = 'insert';
}
if (isset($op) && module_exists('menu_link')) {
menu_link_maintain('aggregator', $op, $link_path, $edit['title']);
}
}