You are here

function viewfield_select_process in Viewfield 6

Same name and namespace in other branches
  1. 6.2 viewfield.module \viewfield_select_process()
1 string reference to 'viewfield_select_process'
viewfield_elements in ./viewfield.module
Implementation of FAPI hook_elements().

File

./viewfield.module, line 194
Core functions.

Code

function viewfield_select_process($element, $edit, $form_state, $form) {
  $field = isset($form['#field_info'][$element['#field_name']]) ? $form['#field_info'][$element['#field_name']] : NULL;
  $element['#field_info'] = isset($form['#field_info']) ? $form['#field_info'] : NULL;

  // This form is used for both the default value field in the admin as well as
  // the node edit form, so we have to make sure we show the default value field
  // always.
  $node = isset($form['#node']) ? $form['#node'] : (object) array(
    'type' => $field['type_name'],
  );
  $field_settings = !isset($node->uid);
  if ($field['widget']['force_default'] && !$field_settings) {
    $element['vname'] = array(
      '#type' => 'value',
      '#value' => $element['#default_value']['vname'],
    );
    $element['vargs'] = array(
      '#type' => 'value',
      '#value' => $element['#default_value']['vargs'],
    );
  }
  else {

    // Display the form to let the user pick a view.
    $options = _viewfield_potential_references($field, $element['#delta']);

    // Provide our own overriding of defaults.
    if ($field['super_default'] && !$field_settings) {
      $element['override_default'] = array(
        '#type' => 'checkbox',
        '#title' => t('Override default'),
        '#default_value' => $element['#value']['override_default'],
      );
    }
    if (count($options) > 1) {
      $element['vname'] = array(
        '#type' => 'select',
        '#options' => $options,
        '#default_value' => isset($element['#default_value']['vname']) ? $element['#default_value']['vname'] : NULL,
        '#title' => $element['#title'],
        '#required' => $element['#required'],
        '#description' => $element['#description'],
      );
    }
    else {

      // There's only the one view, so only show the arguments.
      list($key, $label) = each($options);
      $element['vname'] = array(
        '#type' => 'value',
        '#value' => $key,
      );
    }
    $element['vargs'] = array(
      '#type' => 'textfield',
      '#title' => !isset($label) ? t('Arguments') : t('%field (@value) arguments', array(
        '%field' => $field['widget']['label'],
        '@value' => $label,
      )),
      '#default_value' => isset($element['#default_value']['vargs']) ? $element['#default_value']['vargs'] : NULL,
      '#required' => FALSE,
      '#description' => t('Provide a comma separated list of arguments to pass to the view. These arguments will be passed to EACH selected view. If an argument contains commas or double quotes, enclose it in double quotes. Replace double quotes that are part of the argument with pairs of double quotes.'),
    );
    $token_desc = ($token_enabled = _viewfield_token_enabled($field)) ? t('Use the syntax [token] if you want to insert a replacement pattern.') : t('You may use %nid for the node id of the current node. %author for the node author and %viewer for user viewing the node.');
    $element['vargs']['#description'] .= "<br/>\n{$token_desc}";

    // Since tabledrag.js currently cannot handle nested tables, we show the
    // token help inside the fieldset only in the field settings form or in
    // single-value mode.
    if ($token_enabled && ($field_settings || !$field['multiple'])) {
      $element['token_help'] = _viewfield_get_token_help($field);
    }
  }
  return $element;
}