You are here

function recipe_import_form in Recipe 7

Same name and namespace in other branches
  1. 6 recipe.module \recipe_import_form()
  2. 7.2 recipe.admin.inc \recipe_import_form()

Page callback: Constructs a form for importing a single recipe.

See also

recipe_menu()

recipe_import_form_build_preview()

recipe_import_form_validate()

recipe_import_form_submit()

1 string reference to 'recipe_import_form'
recipe_menu in ./recipe.module
Implements hook_menu().

File

./recipe.module, line 1490
Contains functions for Recipe node CRUD and display.

Code

function recipe_import_form($form, &$form_state) {
  $formats = module_invoke_all('recipeio', 'import_single');
  $options = array();
  foreach ($formats as $format) {
    $options[$format['callback']] = $format['format_name'];
  }

  // Some special stuff when previewing a node.
  if (isset($form_state['node_preview'])) {
    $form['#prefix'] = $form_state['node_preview'];
  }
  $form['recipe_format'] = array(
    '#type' => 'select',
    '#title' => t('Recipe format'),
    '#options' => $options,
    '#default_value' => !empty($form_state['values']['recipe_format']) ? $form_state['values']['recipe_format'] : '',
    '#size' => 1,
    '#description' => t('The recipe input format.'),
  );
  $form['recipe_import_text'] = array(
    '#type' => 'textarea',
    '#title' => t('Paste import data here'),
    '#default_value' => !empty($form_state['values']['recipe_import_text']) ? $form_state['values']['recipe_import_text'] : '',
    '#cols' => 55,
    '#rows' => 8,
    '#required' => TRUE,
    '#description' => t('Use 1 blank line between sections: Description, Ingredients, Instructions, Notes. Always use preview first to avoid unintended consequences.'),
    '#attributes' => array(
      'class' => array(
        'recipe-import-text',
      ),
    ),
  );
  $form['buttons']['preview'] = array(
    '#type' => 'submit',
    '#value' => t('Preview'),
    '#weight' => 1,
    '#submit' => array(
      'recipe_import_form_build_preview',
    ),
  );
  $form['buttons']['import'] = array(
    '#type' => 'submit',
    '#value' => t('Import'),
    '#weight' => 2,
    '#submit' => array(
      'recipe_import_form_submit',
    ),
  );
  return $form;
}