function aggregator_save_category

Adds/edits/deletes aggregator categories.

Parameters

$edit: An associative array describing the category to be added/edited/deleted.

1 call to aggregator_save_category()
aggregator_form_category_submit in drupal/core/modules/aggregator/aggregator.admin.inc
Form submission handler for aggregator_form_category().

File

drupal/core/modules/aggregator/aggregator.module, line 329
Used to aggregate syndicated content (RSS, RDF, and Atom).

Code

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']);
  }
}