Last active
December 22, 2015 11:39
-
-
Save Greg-Boggs/6467483 to your computer and use it in GitHub Desktop.
Blockforms code to save the current page NID to a entityreference field in the embedded form.
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 | |
/** | |
* Implements node_presave to attach the current node's nid as an entity reference in the node being saved in a block form. | |
* This code requires 'journal_entry' form to be embedded on a 'course' with the formblock module and the journal_entry type must | |
* have an entity reference field called 'field_course_reference' | |
*/ | |
function ucg_node_presave($node) { | |
$journal_wrapper = entity_metadata_wrapper('node', $node); | |
if($journal_wrapper->getBundle() == 'journal_entry') { | |
if (arg(0) == 'node' && is_numeric(arg(1))) { | |
$course_node = node_load(arg(1)); | |
$course_wrapper = entity_metadata_wrapper('node', $course_node); | |
if($course_wrapper->getBundle() == 'course') { | |
$course_nid = intval($course_wrapper->nid->value()); | |
$journal_wrapper->field_course_reference->set($course_nid); | |
} | |
} | |
} | |
return $node; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment