node_add_form.inc

  1. cis7 sites/all/modules/ulmus/ctools/plugins/contexts/node_add_form.inc
  2. cle7 sites/all/modules/ulmus/ctools/plugins/contexts/node_add_form.inc
  3. ecd7 sites/all/modules/ulmus/ctools/plugins/contexts/node_add_form.inc
  4. elmsmedia7 sites/all/modules/ulmus/ctools/plugins/contexts/node_add_form.inc
  5. harmony7 sites/all/modules/ulmus/ctools/plugins/contexts/node_add_form.inc
  6. icor7 sites/all/modules/ulmus/ctools/plugins/contexts/node_add_form.inc
  7. meedjum_blog7 sites/all/modules/ulmus/ctools/plugins/contexts/node_add_form.inc
  8. mooc7 sites/all/modules/ulmus/ctools/plugins/contexts/node_add_form.inc

Plugin to provide a node_add_form context

Functions

Namesort descending Description
ctools_context_create_node_add_form It's important to remember that $conf is optional here, because contexts are not always created from the UI.
ctools_context_node_add_form_convert Convert a context into a string.
ctools_context_node_add_form_settings_form
ctools_context_node_add_form_settings_form_submit

File

sites/all/modules/ulmus/ctools/plugins/contexts/node_add_form.inc
View source
  1. <?php
  2. /**
  3. * @file
  4. *
  5. * Plugin to provide a node_add_form context
  6. */
  7. /**
  8. * Plugins are described by creating a $plugin array which will be used
  9. * by the system that includes this file.
  10. */
  11. $plugin = array(
  12. 'title' => t('Node add form'),
  13. 'description' => t('A node add form.'),
  14. 'context' => 'ctools_context_create_node_add_form',
  15. 'edit form' => 'ctools_context_node_add_form_settings_form',
  16. 'defaults' => array('type' => ''),
  17. 'keyword' => 'node_add',
  18. 'context name' => 'node_add_form',
  19. 'convert list' => array('type' => t('Node type')),
  20. 'convert' => 'ctools_context_node_add_form_convert',
  21. 'placeholder form' => array(
  22. '#type' => 'textfield',
  23. '#description' => t('Enter the node type this context.'),
  24. ),
  25. );
  26. /**
  27. * It's important to remember that $conf is optional here, because contexts
  28. * are not always created from the UI.
  29. */
  30. function ctools_context_create_node_add_form($empty, $data = NULL, $conf = FALSE) {
  31. static $creating = FALSE;
  32. $context = new ctools_context(array('form', 'node_add', 'node_form', 'node', 'entity:node'));
  33. $context->plugin = 'node_add_form';
  34. if ($empty || ($creating)) {
  35. return $context;
  36. }
  37. $creating = TRUE;
  38. if ($conf && (isset($data['types']) || isset($data['type']))) {
  39. // Holdover from typo'd config.
  40. $data = isset($data['types']) ? $data['types'] : $data['type'];
  41. }
  42. if (!empty($data)) {
  43. $types = node_type_get_types();
  44. $type = str_replace('-', '_', $data);
  45. // Validate the node type exists.
  46. if (isset($types[$type]) && node_access('create', $type)) {
  47. // Initialize settings:
  48. global $user;
  49. $node = (object) array(
  50. 'uid' => $user->uid,
  51. 'name' => (isset($user->name) ? $user->name : ''),
  52. 'type' => $type,
  53. 'language' => LANGUAGE_NONE,
  54. );
  55. $form_id = $type . '_node_form';
  56. $form_state = array(
  57. 'want form' => TRUE,
  58. 'build_info' => array(
  59. 'args' => array($node)
  60. )
  61. );
  62. // Use module_load_include so that caches and stuff can know to load this.
  63. form_load_include($form_state, 'inc', 'node', 'node.pages');
  64. $form = drupal_build_form($form_id, $form_state);
  65. // In a form, $data is the object being edited.
  66. $context->data = $node;
  67. $context->title = $types[$type]->name;
  68. $context->argument = $type;
  69. // These are specific pieces of data to this form.
  70. // All forms should place the form here.
  71. $context->form = $form;
  72. $context->form_id = $form_id;
  73. $context->form_title = t('Submit @name', array('@name' => $types[$type]->name));
  74. $context->node_type = $type;
  75. $context->restrictions['type'] = array($type);
  76. $context->restrictions['form'] = array('form');
  77. $creating = FALSE;
  78. return $context;
  79. }
  80. }
  81. $creating = FALSE;
  82. }
  83. function ctools_context_node_add_form_settings_form($form, &$form_state) {
  84. $conf = $form_state['conf'];
  85. $form['type'] = array(
  86. '#title' => t('Node type'),
  87. '#type' => 'select',
  88. '#options' => node_type_get_names(),
  89. '#default_value' => $conf['type'],
  90. '#description' => t('Select the node type for this form.'),
  91. );
  92. return $form;
  93. }
  94. function ctools_context_node_add_form_settings_form_submit($form, &$form_state) {
  95. $form_state['conf']['type'] = $form_state['values']['type'];
  96. }
  97. /**
  98. * Convert a context into a string.
  99. */
  100. function ctools_context_node_add_form_convert($context, $type) {
  101. switch ($type) {
  102. case 'type':
  103. return $context->data->type;
  104. }
  105. }
Error | ELMSLN API

Error

×

Error message

  • Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/elmsln_community/api.elmsln.org/includes/common.inc:2791) in drupal_send_headers() (line 1499 of /var/www/html/elmsln_community/api.elmsln.org/includes/bootstrap.inc).
  • Error: Call to undefined function apc_delete() in DrupalAPCCache->clear() (line 289 of /var/www/html/elmsln_community/api.elmsln.org/sites/all/modules/apc/drupal_apc_cache.inc).
The website encountered an unexpected error. Please try again later.