| [ Index ] |
PHP Cross Reference of Drupal 6 (gatewave) |
[Summary view] [Print] [Text view]
1 <?php 2 // $Id: node_add_form.inc,v 1.9.2.3 2010/07/20 20:49:21 merlinofchaos Exp $ 3 4 /** 5 * @file 6 * 7 * Plugin to provide a node_add_form context 8 */ 9 10 /** 11 * Plugins are described by creating a $plugin array which will be used 12 * by the system that includes this file. 13 */ 14 $plugin = array( 15 'title' => t("Node add form"), 16 'description' => t('A node add form.'), 17 'context' => 'ctools_context_create_node_add_form', 18 'settings form' => 'ctools_context_node_add_form_settings_form', 19 'keyword' => 'node_add', 20 'context name' => 'node_add_form', 21 'convert list' => array('type' => t('Node type')), 22 'convert' => 'ctools_context_node_add_form_convert', 23 'placeholder form' => array( 24 '#type' => 'textfield', 25 '#description' => t('Enter the node type this context.'), 26 ), 27 ); 28 29 /** 30 * It's important to remember that $conf is optional here, because contexts 31 * are not always created from the UI. 32 */ 33 function ctools_context_create_node_add_form($empty, $data = NULL, $conf = FALSE) { 34 static $created; 35 $context = new ctools_context(array('form', 'node_add', 'node_form')); 36 $context->plugin = 'node_add_form'; 37 38 if ($empty || (isset($created) && $created)) { 39 return $context; 40 } 41 $created = TRUE; 42 43 if ($conf && (isset($data['types']) || isset($data['type']))) { 44 // Holdover from typo'd config. 45 $data = isset($data['types']) ? $data['types'] : $data['type']; 46 } 47 48 if (!empty($data)) { 49 $types = node_get_types(); 50 $type = str_replace('-', '_', $data); 51 52 // Validate the node type exists. 53 if (isset($types[$type]) && node_access('create', $type)) { 54 // Initialize settings: 55 global $user; 56 $node = array('uid' => $user->uid, 'name' => $user->name, 'type' => $type); 57 58 ctools_include('form'); 59 $form_id = $node['type'] . '_node_form'; 60 61 $form_state = array('want form' => TRUE, 'args' => array($node)); 62 63 $file = drupal_get_path('module', 'node') . '/node.pages.inc'; 64 include_once './' . $file; 65 // This piece of information can let other modules know that more files 66 // need to be included if this form is loaded from cache: 67 $form_state['form_load_files'] = array($file); 68 69 $form = ctools_build_form($form_id, $form_state); 70 // In a form, $data is the object being edited. 71 $context->data = $type; 72 $context->title = $types[$type]->name; 73 $context->argument = $type; 74 75 // These are specific pieces of data to this form. 76 // All forms should place the form here. 77 $context->form = $form; 78 $context->form_id = $type . '_node_form'; 79 $context->form_title = t('Submit @name', array('@name' => $types[$type]->name)); 80 $context->node_type = $type; 81 $context->restrictions['type'] = array($type); 82 return $context; 83 } 84 } 85 } 86 87 function ctools_context_node_add_form_settings_form($conf) { 88 foreach (node_get_types() as $type => $info) { 89 $options[$type] = $info->name; 90 } 91 asort($options); 92 93 if (isset($conf['types']) && !isset($conf['type'])) { 94 $conf['type'] = $conf['types']; 95 } 96 if (empty($conf)) { 97 $conf = array('type' => ''); 98 } 99 100 $form['type'] = array( 101 '#title' => t('Node type'), 102 '#type' => 'select', 103 '#options' => $options, 104 '#default_value' => $conf['type'], 105 '#description' => t('Select the node type for this form.'), 106 ); 107 108 return $form; 109 } 110 111 /** 112 * Convert a context into a string. 113 */ 114 function ctools_context_node_add_form_convert($context, $type) { 115 switch ($type) { 116 case 'type': 117 return $context->data; 118 } 119 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Thu Mar 24 11:18:33 2011 | Cross-referenced by PHPXref 0.7 |