Created
July 22, 2015 01:35
-
-
Save rscotton/a4a8678182dd244a0f2b to your computer and use it in GitHub Desktop.
Duke Scholars Add Scholar 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 | |
/* | |
* Demonstrate setting up Add Scholar page in Drupal | |
*/ | |
function dom_scholars_menu() { | |
$items = array(); | |
//Use drupal_get_form and pass custom form below as an argument in order to pull form to page | |
$items['add-scholar'] = array( | |
'title' => 'Add Scholar', | |
'page callback' => 'drupal_get_form', | |
'page arguments' => array('dom_scholars_add_form'), | |
'access callback' => '_dom_scholars_access', | |
); | |
return $items; | |
} | |
//See Drupal form API: https://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7 | |
function dom_scholars_add_form($form, &$form_state) { | |
switch (current_path()) { | |
case 'add-scholar': | |
$form['scholar_id'] = array( | |
'#type' => 'textfield', | |
'#title' => 'Scholar Id', | |
); | |
$form['actions'] = array( | |
'#type' => 'actions', | |
); | |
$form['actions']['submit'] = array( | |
'#type' => 'submit', | |
'#value' => 'Add Scholar', | |
); | |
$form['#submit'][] = 'dom_scholars_add_form_submit'; | |
break; | |
} | |
return $form; | |
} | |
function dom_scholars_add_form_submit($form, &$form_state) { | |
switch (current_path()) { | |
case 'add-scholar': | |
if (!empty($form_state['values']['scholar_id'])) { | |
_dom_scholars_retrieve_content($form_state['values']['scholar_id']); //Call core import function | |
} | |
else { | |
drupal_set_message(t('You must provide a scholar id.'), 'error'); | |
} | |
break; | |
} | |
} | |
//Only allow administrators to add scholars | |
function _dom_scholars_access() { | |
global $user; | |
return in_array('administrator', $user->roles); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment