Skip to content

Instantly share code, notes, and snippets.

@Greg-Boggs
Created March 19, 2014 23:02
Show Gist options
  • Save Greg-Boggs/9653350 to your computer and use it in GitHub Desktop.
Save Greg-Boggs/9653350 to your computer and use it in GitHub Desktop.
useful with formblock to save the parent node to the created node's reference field
<?php
function HOOK_ugc_node_presave($node) {
$journal_wrapper = entity_metadata_wrapper('node', $node);
// If this is a new journal entry set it's parent reference.
if ($journal_wrapper->getBundle() == 'journal_entry') {
// If this is the first time the journal is saved, attach the course.
if (!$journal_wrapper->getIdentifier() && arg(0) == 'node' && is_numeric(arg(1))) {
$course_wrapper = entity_metadata_wrapper('node', arg(1));
$journal_wrapper->field_course_reference->set(arg(1));
}
}
}
?>
@barraponto
Copy link

What is $course_wrapper created for?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment