Created
March 19, 2014 23:02
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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)); | |
} | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What is
$course_wrapper
created for?