function content_edit_content_form_submit

7.x content.module content_edit_content_form_submit(&$form, &$form_state)
6.x content.module content_edit_content_form_submit(&$form, &$form_state)
4.x content.module content_edit_content_form_submit(&$form, $form_state)
5.x content.module content_edit_content_form_submit(&$form, $form_state)

Submit handler for the edit content form.

_state

Parameters

unknown_type $form:

File

modules/content/content.module, line 353

Code

function content_edit_content_form_submit(&$form, $form_state) {
  global $user;

  $values = $form_state ["values"];

  $now = time();

  $types = content_get_types();
  $type = $values ["type"];

  // Does the user have permission to edit this content?
  if (!user_has_permission("edit_$type" . "_content")) {
    fp_add_message(t("Sorry, you do not have permission to edit that content type."));
    fp_goto("admin/config/content");
    return;
  }


  // Assemble our "settings" array, if available.
  $settings = array();
  if (is_array($types [$type]["settings"])) {

    foreach ($types [$type]["settings"] as $field_name => $field_details) {
      $settings [$field_name] = $values [$field_name];
    }
  }


  if ($values ["submit_submit"] != "") {
    // a submission (not a deletion) is taking place

    // if the cid == "new" then we should do an insert.  Otherwise,
    // we should do an update.
    if ($values ["cid"] == "new") {
      db_query("INSERT INTO content (user_id, type, title, body, settings, posted, updated)
                VALUES ('?', '?', '?', '?', '?', '?', '?')
                ", $user->id, $values ["type"], $values ["title"], $values ["body"], serialize($settings), $now, $now);

      $new_id = db_insert_id();

      $form ["#redirect"] = array(
        "path" => "content/$new_id/edit",
      );


    }
    else {
      // We are editing an existing piece of content-- just update.
      db_query("UPDATE content
                SET title = '?',
                    body = '?',
                    settings = '?',
                    updated = '?'
                WHERE cid = '?'
                ", $values ["title"], $values ["body"], serialize($settings), $now, $values ["cid"]);

    }

    fp_add_message(t("%title has been saved successfully.", array("%title" => $values ["title"])));


  }

  // Should be we deleting things?
  if ($values ["submit_delete"] != "") {
    db_query("DELETE FROM content WHERE cid = '?' ", $values ["cid"]);
    fp_add_message(t("%title has been deleted successfully.", array("%title" => $values ["title"])));
    $form ["#redirect"] = array(
      "path" => "admin/config/content",
    );
  }


}