You are here

function boxes_form in Boxes 7.2

Boxes form

2 string references to 'boxes_form'
boxes_add in includes/boxes.pages.inc
Add box page callback
boxes_edit in includes/boxes.pages.inc
Edit box page callback

File

includes/boxes.pages.inc, line 170
Box Functions

Code

function boxes_form($form, &$form_state, Box $box, $type = NULL) {

  // During initial form build, add the box entity to the form state for use
  // during form building and processing. During a rebuild, use what is in the
  // form state.
  if (!isset($form_state['box'])) {
    if (!isset($box->label)) {
      $box->label = NULL;
    }
    if (isset($type)) {
      $box->type = $type;
    }
    $form_state['box'] = $box;
  }
  else {
    $box = $form_state['box'];
  }
  $form['label'] = array(
    '#type' => 'textfield',
    '#title' => t('Label'),
    '#required' => TRUE,
    '#default_value' => $box->label,
    '#description' => t('Name that displays in the admin interface'),
    '#weight' => -10,
  );
  $form['title'] = array(
    '#type' => 'textfield',
    '#title' => t('Title'),
    '#description' => t('The Title of the block.'),
    '#default_value' => $box->title,
    '#weight' => -9,
  );

  // The view mode.
  if (user_access('edit box view mode')) {
    $box_info = $box
      ->entityInfo();
    $view_modes = array_keys($box_info['view modes']);
    $view_modes = array_combine($view_modes, $view_modes);
    $form['view_mode'] = array(
      '#title' => t('View Mode'),
      '#description' => t('Edit the view mode of the Box'),
      '#default_value' => $box->view_mode,
      '#type' => 'select',
      '#required' => TRUE,
      '#options' => $view_modes,
      '#weight' => -8,
    );
  }
  else {
    $form['view_mode'] = array(
      '#type' => 'value',
      '#value' => $box->view_mode,
    );
  }
  $form['box'] = array(
    '#type' => 'value',
    '#value' => $box,
  );

  // Get the Box type form.
  $form += $box
    ->getForm($form, $form_state);

  // Add the buttons.
  $form['actions'] = array(
    '#type' => 'actions',
  );
  $form['actions']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save'),
    '#weight' => 200,
    '#submit' => array(
      'boxes_form_submit',
    ),
  );
  if (!empty($box->bid) && user_access('delete any ' . $box->type . ' box')) {
    $form['actions']['delete'] = array(
      '#type' => 'submit',
      '#value' => t('Delete'),
      '#weight' => 201,
      '#submit' => array(
        'boxes_form_delete_submit',
      ),
    );
  }
  $form['#validate'][] = 'boxes_form_validate';
  if (!isset($form['#submit']) && function_exists($box->type . '_boxes_form_submit')) {
    $form['#submit'][] = $box->type . '_boxes_form_submit';
  }
  $form += array(
    '#submit' => array(),
  );
  field_attach_form('box', $box, $form, $form_state);
  return $form;
}