You are here

function botcha_recipebook_form in BOTCHA Spam Prevention 7.2

Same name and namespace in other branches
  1. 6.2 botcha.admin.inc \botcha_recipebook_form()

Edit existent or add a new recipe book.

Parameters

array $form: Form API form array.

array $form_state: Form API form state array.

BotchaRecipebook $recipebook: Recipe book object.

2 string references to 'botcha_recipebook_form'
botcha_menu in ./botcha.module
Implements hook_menu().
botcha_update_7200 in ./botcha.install
Create flexible relationships between recipe books and recipes and between recipe books and forms.

File

./botcha.admin.inc, line 129
Implementation of botcha administration forms.

Code

function botcha_recipebook_form($form, &$form_state, $recipebook = NULL) {

  // Determine default values depending on whether we add or edit recipe book.
  // Form a list of recipes.
  $options_recipes = array();
  foreach (Botcha::getRecipes() as $recipe) {
    $options_recipes[$recipe->id] = $recipe->title;
  }
  if (empty($recipebook)) {
    $disabled_id = FALSE;
    $default_id = '';
    $default_title = '';
    $default_description = '';
    $default_recipes = array();
    $button = t('Add');
  }
  else {
    $disabled_id = TRUE;
    $default_id = $recipebook->id;
    $default_title = $recipebook->title;
    $default_description = $recipebook->description;
    $default_recipes = array_keys($recipebook
      ->getRecipes());
    $button = t('Save');
  }
  $form['id'] = array(
    '#type' => 'machine_name',
    '#default_value' => $default_id,
    '#disabled' => $disabled_id,
    '#maxlength' => 128,
    '#machine_name' => array(
      'exists' => 'botcha_recipebook_exists',
    ),
  );
  $form['title'] = array(
    '#type' => 'textfield',
    '#title' => t('Title'),
    '#description' => t('A title for this recipe book. You can always change this name later.'),
    '#default_value' => $default_title,
    '#required' => TRUE,
    '#maxlength' => 128,
  );
  $form['description'] = array(
    '#type' => 'textarea',
    '#rows' => 5,
    '#title' => t('Description'),
    '#description' => t('A description of the recipe book.'),
    '#default_value' => $default_description,
  );
  $form['recipes'] = array(
    '#type' => 'checkboxes',
    '#title' => t('Recipes'),
    '#description' => t('Choose what recipes are included in recipe book.'),
    '#options' => $options_recipes,
    '#default_value' => $default_recipes,
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => $button,
  );
  return $form;
}