You are here

function viewfield_select_process in Viewfield 6.2

Same name and namespace in other branches
  1. 6 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 211
Core functions.

Code

function viewfield_select_process($element, $edit, $form_state, $form) {

  // 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.
  $is_field_settings_form = !isset($form['#node']);
  $field = isset($form['#field_info'][$element['#field_name']]) ? $form['#field_info'][$element['#field_name']] : NULL;
  $element['#field'] = $field;

  // Display the form to let the user pick a view.
  $options = _viewfield_potential_references($field, $element['#delta']);
  $element['vname'] = array(
    '#type' => 'select',
    '#title' => $element['#title'],
    '#options' => $options,
    '#default_value' => isset($element['#default_value']['vname']) ? $element['#default_value']['vname'] : NULL,
    '#required' => $element['#required'],
    '#access' => $is_field_settings_form || !$field['widget']['force_default'],
    '#description' => $element['#description'],
  );

  // If there is only one option, only show arguments.
  if (count($options) == 1 && !$is_field_settings_form) {
    list($key, $label) = each($options);
    $element['vname']['#access'] = FALSE;
    $element['vname']['#default_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,
    '#access' => $is_field_settings_form || !$field['widget']['force_default'],
    '#description' => t('A comma separated list of arguments to pass to the selected view. Wrap arguments containing commas in double quotes. Replace double quotes in arguments with two double quotes.'),
  );
  $token_description = t('Available tokens: %nid for the id of the current node; %author for the node author; %viewer for the viewing user');
  if (module_exists('token')) {
    $element['vargs']['#description'] .= '<br />' . $token_description . '; ' . t('or any token from the placeholder token list.') . '<br />' . t('Note: Using placeholder tokens in combination with the %fields row style may negatively affect site performance.', array(
      '%fields' => t('Fields'),
    ));

    // Only show token help for first value or in field settings form.
    if ($element['#delta'] == 0 && ($is_field_settings_form || !$field['widget']['force_default'])) {
      $element['token_help'] = array(
        '#type' => 'fieldset',
        '#title' => t('Placeholder tokens'),
        '#collapsible' => TRUE,
        '#collapsed' => TRUE,
      );
      $element['token_help']['tokens'] = array(
        '#value' => theme('token_help', 'node'),
      );
    }
  }
  else {
    $element['vargs']['#description'] .= '<br />' . $token_description . '.';
  }
  return $element;
}