As stated in the snippet below, the save function uses $_POST to get to the license data and this is not the Drupal way. Instead, it should get the data from the $node object. A case where this causes a bug is when an action is triggered to update a node and there is no POST data.

/**
 * Save license/node relationship in database
 */
function creativecommons_save($node, $op) {
  //TODO: shouldn't be using $_POST... what's the drupal way to do this? use submit instead?
  $cc = new creativecommons_license($_POST['creativecommons']['select_license_form']['cc_license_uri'], $_POST['creativecommons']['metadata']);
  $cc->save($node->nid, $op);
}
CommentFileSizeAuthor
#2 creativecommons-save.patch1.2 KBtoemaz

Comments

toemaz’s picture

The fix:

/**
 * Save license/node relationship in database
 */
function creativecommons_save($node, $op) {
  
  // form submits data in creativecommons, while node_load stores it in cc
  if (isset($node->creativecommons)) {
    $cc_license_uri = $node->creativecommons['select_license_form']['cc_license_uri'];
    $metadata = $node->creativecommons['metadata'];
  }
  else {
    $cc_license_uri = $node->cc->uri;
    $metadata = $node->cc->metadata;
  }
  
  $cc = new creativecommons_license($cc_license_uri, $metadata);
  $cc->save($node->nid, $op);
}
toemaz’s picture

Status: Active » Needs review
StatusFileSize
new1.2 KB

Here is the patch.

turadg’s picture

Status: Needs review » Fixed

Excellent, thanks.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.