You are here

function webform_components_form in Webform 5.2

Same name and namespace in other branches
  1. 6.3 includes/webform.components.inc \webform_components_form()
  2. 6.2 webform_components.inc \webform_components_form()
  3. 7.4 includes/webform.components.inc \webform_components_form()
  4. 7.3 includes/webform.components.inc \webform_components_form()

Overview form of all components for this webform.

1 string reference to 'webform_components_form'
webform_components in ./webform.module
Menu callback for node/[nid]/components.

File

./webform_components.inc, line 17
Webform module components handling.

Code

function webform_components_form($node) {
  $form = array(
    '#tree' => TRUE,
    '#node' => $node,
    'components' => array(),
  );
  $form['nid'] = array(
    '#type' => 'value',
    '#value' => $node->nid,
  );
  $options = array();
  foreach ($node->webform['components'] as $cid => $component) {
    $options[$cid] = check_plain($component['name']);
    $form['components'][$cid]['cid'] = array(
      '#type' => 'hidden',
      '#default_value' => $component['cid'],
    );
    $form['components'][$cid]['pid'] = array(
      '#type' => 'hidden',
      '#default_value' => $component['pid'],
    );
    $form['components'][$cid]['weight'] = array(
      '#type' => 'weight',
      '#delta' => count($node->webform['components']) > 10 ? count($node->webform['components']) : 10,
      '#title' => t('Weight'),
      '#default_value' => $component['weight'],
    );
    $form['components'][$cid]['mandatory'] = array(
      '#type' => 'checkbox',
      '#title' => t('Mandatory'),
      '#default_value' => $component['mandatory'],
      '#access' => !in_array($component['type'], array(
        'markup',
        'fieldset',
        'pagebreak',
      )),
    );
    $form['components'][$cid]['email'] = array(
      '#type' => 'checkbox',
      '#title' => t('E-mail'),
      '#default_value' => $component['email'],
      '#access' => !in_array($component['type'], array(
        'markup',
        'fieldset',
        'pagebreak',
      )),
    );
  }
  $form['add']['name'] = array(
    '#type' => 'textfield',
    '#size' => 24,
  );
  $component_types = webform_load_components();
  natcasesort($component_types);
  $form['add']['type'] = array(
    '#type' => 'select',
    '#options' => $component_types,
    '#weight' => 3,
    '#default_value' => isset($_GET['cid']) && isset($node->webform['components'][$_GET['cid']]) ? $node->webform['components'][$_GET['cid']]['type'] : 'textfield',
  );
  $form['add']['mandatory'] = array(
    '#type' => 'checkbox',
  );
  $form['add']['email'] = array(
    '#type' => 'checkbox',
    '#default_value' => 1,
  );
  $form['add']['cid'] = array(
    '#type' => 'hidden',
    '#default_value' => '',
  );
  $form['add']['pid'] = array(
    '#type' => 'hidden',
    '#default_value' => isset($_GET['cid']) && isset($node->webform['components'][$_GET['cid']]) ? $node->webform['components'][$_GET['cid']]['pid'] : 0,
  );
  $form['add']['weight'] = array(
    '#type' => 'weight',
    '#delta' => count($node->webform['components']) > 10 ? count($node->webform['components']) : 10,
    '#default_value' => isset($_GET['cid']) && isset($node->webform['components'][$_GET['cid']]) ? $node->webform['components'][$_GET['cid']]['weight'] + 1 : count($node->webform['components']),
  );
  $form['add']['add'] = array(
    '#type' => 'submit',
    '#value' => t('Add'),
    '#weight' => 45,
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Submit'),
    '#weight' => 45,
  );
  $form['publish'] = array(
    '#type' => 'submit',
    '#value' => t('Publish'),
    '#weight' => 50,
    '#access' => !$node->status,
  );
  return $form;
}