Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.10 KB | None | 0 0
  1. //Work out the form stuff.
  2. function missionary_profiles_wall_form($form, &$form_state) {
  3.   $title = drupal_get_title();
  4.   $temp = node_add('missionary_update');
  5.  
  6.   //get the actual value of the missionary id.
  7.   $arg = arg(2);
  8.    
  9.     //$form['#node_edit_form'] = TRUE;
  10.     //$form['#attributes'] = $temp['#attributes'];
  11.     //$form['#entity_type'] = 'node';
  12.     //$form['#bundle']  = 'missionary_update';
  13.     $form['nid'] = $temp['nid'];
  14.     $form['vid'] = $temp['vid'];
  15.     $form['uid'] = $temp['uid'];
  16.     $form['created'] = $temp['created'];
  17.     $form['language'] = $temp['language'];
  18.     $form['changed']    = $temp['changed'];
  19.     //$form['#node']    = $temp['#node'];
  20.     $form['type'] = $temp['type'];
  21.     $form['title'] = $temp['title'];
  22.     $form['body']    = $temp['body'];  
  23.    
  24.     //replace any hyphens with white space.
  25.     $arg = str_replace("-", " ", $arg);
  26.     $terms = taxonomy_get_term_by_name($arg);
  27.     $termid = NULL;
  28.    
  29.     //for now we'll just use the first one - introdduce more useful checking later.
  30.     //@todo: check vocabularies
  31.     foreach($terms as $tid => $term) {
  32.         $termid = $tid;
  33.         break;
  34.     }
  35.    
  36.     if($termid != NULL) {
  37.         $form['field_missionary'] = array('#type'   => 'hidden',
  38.                                                                             '#value'    => $termid,
  39.                                                                             '#name' => 'field_missionary[und]',
  40.                                                                             '#id'       => 'edit-field-missionary-und');
  41.     }
  42.    
  43.     $form['author'] = array('#type' => 'hidden');
  44.     $form['status'] = array('#type' => 'hidden',
  45.                                                     '#value'=> $temp['additional_settings']['group']['#groups']['additional_settings'][2]['status']['#default_value'],
  46.                                                     '#name' => 'status',
  47.                                                     '#id'   => 'edit-status',);
  48.    
  49.     unset($temp);
  50.                                                    
  51.     //set the action to the right adress
  52.     //$form['#action'] = '/blockstest/'.$_GET['q'];
  53.     //#redirect overides the redirect thing in form state.
  54.     //$form['#redirect'] = '/blockstest/'.$_GET['q'];
  55.  
  56.   $form['actions'] = array(
  57.         '#type' => 'actions',
  58.         'submit'=> array(
  59.                                 '#type' => 'submit',
  60.                                 '#value' => t('Save'),
  61.                              ),
  62.         '#id'       => 'edit-actions',
  63.     );
  64.    
  65.   //reset the title back to its original state
  66.     drupal_set_title($title);
  67.    
  68.     //@todo - hide text format options when the setting is filtered html.
  69.     return $form;
  70. }
  71.  
  72. function missionary_profiles_wall_form_validate($form, &$form_state) {
  73.     //validation stuff
  74.     module_load_include('inc', 'node', 'node.pages');
  75.     node_form_validate($form, $form_state);
  76. }
  77.  
  78. function missionary_profiles_wall_form_submit($form, &$form_state) {
  79.     //drupal_set_message(print_r($form['#node'],true) . '<br />' . print_r($form_state,true));
  80.     module_load_include('inc', 'node', 'node.pages');
  81.     node_form_submit($form, $form_state);
  82. }
  83.  
  84. //Define blocks
  85. function missionary_profiles_block_info() {
  86.     $blocks['wall_form'] = array(
  87.         'info'  => t('Wall Update Form'),
  88.         'cache' => DRUPAL_CACHE_PER_PAGE,
  89.     );
  90.    
  91.     return $blocks;
  92. }
  93.  
  94. function missionary_profiles_block_view($delta = '') {
  95.  
  96. module_load_include('inc', 'node', 'node.pages');
  97.    
  98.     switch ($delta) {
  99.         case 'wall_form':
  100.             return array(
  101.                 'subject' => t('Add an Update'),
  102.                 'content' => drupal_get_form('missionary_profiles_wall_form'),
  103.             );
  104.         break;
  105.     }
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement