You are here

function _webform_edit_view in Webform view 7

Same name and namespace in other branches
  1. 7.4 webform_view.inc \_webform_edit_view()

Presents the view options when editing a webform view component.

Allows an editor to select which view to pull in and embed.

Implements _webform_edit_component().

File

./webform_view.inc, line 41
Additional component for webform that allows views to be used as embeddable elements.

Code

function _webform_edit_view($component) {
  $form = array();
  $form['webform_view'] = array(
    '#type' => 'fieldset',
    '#title' => t('Webform View'),
  );
  $options = _webform_view_options();
  $form['webform_view']['view'] = array(
    '#type' => 'select',
    '#title' => t('View'),
    '#options' => $options,
    '#parents' => array(
      'extra',
      'view',
    ),
    '#default_value' => $component['extra']['view'],
    '#description' => t("Choose an existing view that will be embedded in the webform. Each row of this view will be displayed and selections made there will become form fields that will be submitted as part of this form."),
  );

  // Need to expose an option to the editor to choose
  // which of the sub-fields is the trigger or 'quantity' one.
  // If the 'quantity' field is blank, the data for that row
  // is not serialized at all. But the user should not be locked down to
  // 'quantity' as the magic keyword. So we have to expose it instead.
  // To enumerate the subfields, need to look at the current webform proper.
  $webform_node = node_load($component['nid']);
  $subfields = array();
  $subfields['<none>'] = '<none>';
  foreach ($webform_node->webform['components'] as $field) {
    if (isset($component['cid']) && $field['pid'] == $component['cid']) {
      $subfields[$field['form_key']] = $field['form_key'];
    }
  }
  $form['webform_view']['filter_field_id'] = array(
    '#type' => 'select',
    '#title' => t('Required field (in rows)'),
    '#options' => $subfields,
    '#parents' => array(
      'extra',
      'filter_field_id',
    ),
    '#default_value' => $component['extra']['filter_field_id'],
    '#description' => t("Rows where this field is blank will be excluded from results, eg set it to the 'quantity' field to discard info when 'quantity' is zero, or set it to the 'yes' field to ignore submissions where the answer is 'no'. This prevents reports from filling up with dozens of lines with 'quantity:0' next to them. If you choose '&lt;none&gt;', then all rows will always be submitted, without any clean-up."),
  );

  // Pass arguments through to the view.
  // Use the same method as Views UI Preview does.
  $form['webform_view']['contextual_filters'] = array(
    '#type' => 'textfield',
    '#title' => t('Contextual filters'),
    '#parents' => array(
      'extra',
      'contextual_filters',
    ),
    '#default_value' => $component['extra']['contextual_filters'],
    '#description' => t('You can pass arguments through to the view. Separate contextual filter values with a "/".'),
  );
  return $form;
}