function content_edit_content_form

7.x content.module content_edit_content_form($type = "", $cid = "")
6.x content.module content_edit_content_form($type = "", $cid = "")
4.x content.module content_edit_content_form($type = "", $cid = "")
5.x content.module content_edit_content_form($type = "", $cid = "")

This form lets the user edit some piece of content

File

modules/content/content.module, line 238

Code

function content_edit_content_form($type = "", $cid = "") {

  $form = array();

  fp_add_css(fp_get_module_path("content") . "/css/content.css");

  if ($type == "") {
    $type = $_REQUEST ["type"];
  }

  if ($cid == "") {
    $cid = $_REQUEST ["cid"];
  }

  $types = content_get_types();


  if ($cid != "new") {
    $content = content_load($cid);
    fp_set_title(t("Editing") . " " . $content ["title"] . "");
    // Re-set $type, just in case the user put the wrong type in the
    // URL
    $type = $content ["type"];
  }
  else {
    // New piece of content
    $content = array();
    fp_set_title(t("Add new") . " " . $types [$type]["title"]);
  }



  // 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;
  }




  $form ["type"] = array(
    "type" => "hidden",
    "value" => $type,
  );

  $form ["cid"] = array(
    "type" => "hidden",
    "value" => $cid,
  );


  $form ["title"] = array(
    "type" => "textfield",
    "label" => t("Title:"),
    "value" => $content ["title"],
    "required" => TRUE,
    "description" => t("To hide the title, you may start
                     it with [hide].  For example: \"[hide] this is a sample.\""),
  );


  $form ["body"] = array(
    "type" => "textarea",
    "label" => t("Body:"),
    "rows" => 15,
    "value" => $content ["body"],
  );

  // Are there any settings we should show?
  if (is_array($types [$type]["settings"])) {
    foreach ($types [$type]["settings"] as $field_name => $field_details) {
      $form [$field_name] = $field_details;
      // Add in default value previously saved, if available.
      $form [$field_name]["value"] = $content ["settings"][$field_name];
    }
  }



  // Draw the controls (buttons)
  $form ["mark" . $m++] = array(
    "value" => "<div class='content-edit-controls'>",
  );

  $form ["submit_submit"] = array(
    "type" => "submit",
    "value" => t("Submit"),
  );

  $form ["submit_delete"] = array(
    "type" => "submit",
    "value" => t("Delete"),
    "confirm" => t('Are you sure you wish to delete this?\nThis action cannot be undone.'),
  );

  $form ["mark" . $m++] = array(
    "value" => "</div>",
  );


  return $form;
}