Last active
February 13, 2024 04:16
-
-
Save argiepiano/c9ac414e3874331f875c7cc057975637 to your computer and use it in GitHub Desktop.
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 | |
// I have removed irrelevant portions!!! | |
/** | |
* Implements hook_menu(). | |
*/ | |
function vhb_menu() { | |
// ... | |
$menu['node/%node/edit/status/%'] = array( // notice the first placeholder: %node. This will auto-load the node with the NID specified in that position, and will pass the fully loaded node to the function. | |
'page callback' => 'backdrop_get_form', | |
'page arguments' => array('vhb_status_change', 1, 4), | |
'access callback' => 'vhb_access_callback', | |
); | |
return $menu; | |
} | |
/** | |
* Form builder. | |
*/ | |
function vhb_status_change($form, $form_state, $node, $status){ | |
global $user; | |
$rolevar = vhb_rolevar($user); | |
if ( $rolevar > 1 && is_numeric(($status))){ | |
$_SESSION['vhb_status_destination'] = $_SERVER['HTTP_REFERER']; | |
$termname=''; | |
$term = taxonomy_term_load($status); | |
if(isset($term->name)){ $termname = $term->name; } | |
// $node=node_load($nid); // This loading is not needed, since we are passing the full node to this function. | |
$node->field_status['und'][0]['tid'] = $status; | |
$note = array(); | |
$note['content_type'] = 'Application'; | |
$note['mode']='Update'; | |
$uid=0; | |
if(isset($user->uid)){ | |
$note['user_link'] = $uid; | |
} | |
$nid=field_get_value($node, 'field_opening', 'target_id'); | |
if(isset($nid)){ | |
$note['content_link']=$nid; | |
} | |
if(isset($org) && $org !='0'){ | |
$note['org'] = $org; | |
} | |
$note['notetext'] = "Application :".$node->title; | |
$form_state['note'] = $note; // IMPORTANT: we "save" the note in $form_state so that we can retrieve it later when the user conrfirms. | |
// The following was moved here from vhb_status_confirm(). | |
$form['#node'] = $node; | |
// Calling confirm_form simply builds the $form array, which we need to RETURN at the end of the function! | |
$form = confirm_form( | |
$form, | |
t('Are you sure you want to change the status on %node-title?', array('%node-title' => $node->title)), | |
$path, | |
t('This action can be undone.'), | |
t('Save'), | |
t('Cancel'), | |
t('Change status'), | |
); | |
} | |
// if $rolevar is NOT <1 or $status is NOT numeric, we need to return something to indicate this. | |
else { | |
$form['nope'] = array( | |
'#markup' => 'Uh, oh! That if statement did not return true, and now we have no form. Let's just return this markup.', | |
); | |
} | |
// Return the built confirm form array. | |
return $form; | |
} | |
/** | |
* Submit handler. | |
* | |
* We ONLY arrive here if the user has confirmed the confirm form! | |
* | |
*/ | |
function vhb_status_change_submit($form, &$form_state) { | |
// We need to retrieve the note we stored above. | |
$note = $form_state['note']; | |
if(!vhb_create_note($note)){ | |
watchdog("VHB_application_status_set", "VHB module: Note build failure."); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment