You are here

function _webform_edit_grid in Webform 7.4

Same name and namespace in other branches
  1. 5.2 components/grid.inc \_webform_edit_grid()
  2. 5 components/grid.inc \_webform_edit_grid()
  3. 6.3 components/grid.inc \_webform_edit_grid()
  4. 6.2 components/grid.inc \_webform_edit_grid()
  5. 7.3 components/grid.inc \_webform_edit_grid()

Implements _webform_edit_component().

File

components/grid.inc, line 59
Webform module grid component.

Code

function _webform_edit_grid($component) {
  $form = array();
  $form['help'] = array(
    '#type' => 'fieldset',
    '#collapsible' => TRUE,
    '#collapsed' => !empty($component['cid']),
    '#title' => t('About options and questions…'),
    '#description' => t('Options and questions may be configured here, in additional nested Select Options components, or even both.'),
    '#weight' => -4,
    'pros_and_cons' => array(
      '#theme' => 'table',
      '#header' => array(
        '',
        t('Options and questions configured <strong>here</strong>'),
        t('Configured in additional <strong>nested</strong> components'),
        t('Both'),
      ),
      '#rows' => array(
        array(
          t('Questions'),
          t('Enter the questions below.'),
          t('Configure and save this grid, then add additional Select Options components nested (indented) below this grid.'),
          t('Additional questions from nested components will be displayed below any questions configured here.'),
        ),
        array(
          t('Options'),
          t('Enter options below.'),
          t('May be different for each question. Initially the same as defined below.'),
          t('Options from additional nested components will be merged with any options configured here.'),
        ),
        array(
          t('Checkboxes'),
          t('No. Radio buttons only.'),
          t('Yes. Some or all questions may be multiple choice with check boxes.'),
          '',
        ),
        array(
          t('Default'),
          t('Yes. Must be same for all questions.'),
          t('Yes. May all be the same or different.'),
          '',
        ),
        array(
          t('Pre-built option lists'),
          t('No.'),
          t('Yes.'),
          '',
        ),
        array(
          t('Required'),
          t('Yes. Must be same for all questions.'),
          t('Yes. May all be the same or different.'),
          '',
        ),
        array(
          t('Question conditionals'),
          t('No.'),
          t('Yes. Individual questions may be used in conditional rules and/or actions.'),
          t('The whole grid may be conditionally shown or required.'),
        ),
        array(
          t('Other types of nested components'),
          t('No.'),
          t('Yes. Other component types may also be included in the grid. They will be displayed where the options would normally be.'),
          '',
        ),
      ),
    ),
  );
  if (module_exists('options_element')) {
    $form['options'] = array(
      '#type' => 'fieldset',
      '#title' => t('Options'),
      '#collapsible' => TRUE,
      '#attributes' => array(
        'class' => array(
          'webform-options-element',
        ),
      ),
      '#element_validate' => array(
        '_webform_edit_validate_options',
      ),
      '#weight' => -3,
    );
    $form['options']['options'] = array(
      '#type' => 'options',
      '#options' => _webform_select_options_from_text($component['extra']['options'], TRUE),
      '#default_value' => $component['value'],
      '#default_value_allowed' => TRUE,
      '#optgroups' => FALSE,
      '#key_type' => 'mixed',
      '#key_type_toggle' => t('Customize option keys (Advanced)'),
      '#key_type_toggled' => $component['extra']['custom_option_keys'],
      '#default_value_pattern' => '^%.+\\[.+\\]$',
      '#description' => t('<strong>Options to select across the top</strong>, such as "Poor" through "Excellent". Indicate the default to the left of the desired item. Use of only alphanumeric characters and underscores is recommended in keys.') . ' ' . theme('webform_token_help'),
    );
    $form['questions'] = array(
      '#type' => 'fieldset',
      '#title' => t('Questions'),
      '#collapsible' => TRUE,
      '#attributes' => array(
        'class' => array(
          'webform-options-element',
        ),
      ),
      '#element_validate' => array(
        '_webform_edit_validate_options',
      ),
      '#weight' => -2,
    );
    $form['questions']['options'] = array(
      '#type' => 'options',
      '#options' => _webform_select_options_from_text($component['extra']['questions'], TRUE),
      '#optgroups' => FALSE,
      '#default_value' => FALSE,
      '#default_value_allowed' => FALSE,
      '#key_type' => 'mixed',
      '#key_type_toggle' => t('Customize question keys (Advanced)'),
      '#key_type_toggled' => $component['extra']['custom_question_keys'],
      '#description' => t('<strong>Questions list down the side of the grid.</strong> For a heading column on the right, append "|" and the right-side heading. Use of only alphanumeric characters and underscores is recommended in keys.') . ' ' . theme('webform_token_help'),
    );
  }
  else {
    $form['extra']['options'] = array(
      '#type' => 'textarea',
      '#title' => t('Options'),
      '#default_value' => $component['extra']['options'],
      '#description' => t('Options to select across the top, such as "Poor" through "Excellent" or "Stronly Disagree" through "Strongly Agree".') . '<p>' . t('One key-value option per line. <strong>Key-value pairs MUST be specified as "safe_key|Some readable option"</strong>. Use of only alphanumeric characters and underscores is recommended in keys.') . '</p>' . theme('webform_token_help'),
      '#cols' => 60,
      '#rows' => 5,
      '#weight' => -3,
      '#wysiwyg' => FALSE,
      '#element_validate' => array(
        '_webform_edit_validate_select',
      ),
    );
    $form['extra']['questions'] = array(
      '#type' => 'textarea',
      '#title' => t('Questions'),
      '#default_value' => $component['extra']['questions'],
      '#description' => t('Questions list down the side of the grid. One question per line. <strong>Key-value pairs MUST be specified as "safe_key|Some readable question"</strong>. For a heading column on the right, append "|" and the right-side heading. Use of only alphanumeric characters and underscores is recommended in keys.') . ' ' . theme('webform_token_help') . ' ' . '<p>' . t('<strong>Or for more control</strong> over the appearance and configuration, create additional additional Select Options or other type components nested under this grid. They will operate as separate components, but be displayed within this grid.') . '</p>',
      '#cols' => 60,
      '#rows' => 5,
      '#weight' => -2,
      '#wysiwyg' => FALSE,
      '#element_validate' => array(
        '_webform_edit_validate_select',
      ),
    );
    $form['value'] = array(
      '#type' => 'textfield',
      '#title' => t('Default value'),
      '#default_value' => $component['value'],
      '#description' => t('The default option of the grid identified by its key.') . ' ' . theme('webform_token_help'),
      '#size' => 60,
      '#maxlength' => 1024,
      '#weight' => 1,
    );
  }
  $form['display']['optrand'] = array(
    '#type' => 'checkbox',
    '#title' => t('Randomize Options'),
    '#default_value' => $component['extra']['optrand'],
    '#description' => t('Randomizes the order of options on the top when they are displayed in the form.'),
    '#parents' => array(
      'extra',
      'optrand',
    ),
  );
  $form['display']['qrand'] = array(
    '#type' => 'checkbox',
    '#title' => t('Randomize Questions'),
    '#default_value' => $component['extra']['qrand'],
    '#description' => t('Randomize the order of the questions on the side when they are displayed in the form.'),
    '#parents' => array(
      'extra',
      'qrand',
    ),
  );
  $form['display']['sticky'] = array(
    '#type' => 'checkbox',
    '#title' => t('Sticky table header'),
    '#default_value' => $component['extra']['sticky'],
    '#description' => t('Use a sticky (non-scrolling) table header.'),
    '#parents' => array(
      'extra',
      'sticky',
    ),
  );
  $form['validation']['unique'] = array(
    '#type' => 'checkbox',
    '#title' => t('Unique'),
    '#return_value' => 1,
    '#description' => t('Check that all entered values for this field are unique. The same value is not allowed to be used twice.'),
    '#weight' => 1,
    '#default_value' => $component['extra']['unique'],
    '#parents' => array(
      'extra',
      'unique',
    ),
  );
  return $form;
}