You are here

function _views_send_get_fields_and_tokens in Views Send 6

Same name and namespace in other branches
  1. 8 views_send.module \_views_send_get_fields_and_tokens()
  2. 7 views_send.module \_views_send_get_fields_and_tokens()

Generates and returns fields and tokens.

1 call to _views_send_get_fields_and_tokens()
views_send_mail_action_form in ./views_send.module
Configuration form for views_send_mail action.

File

./views_send.module, line 1010
The Views Send module.

Code

function _views_send_get_fields_and_tokens($view, $type) {
  static $return;
  if (isset($return[$type])) {
    return $return[$type];
  }
  if (!in_array($type, array(
    'fields',
    'tokens',
    'fields_name_text',
  )) || !$view) {
    return array();
  }
  $fields = array();
  $tokens = array();
  $fields_name_text = array();
  foreach ($view->field as $field_name => $field) {
    if (!empty($field->content_field)) {
      $field_key = $field_name;
      $field_name = $field->content_field['field_name'];
    }
    elseif (property_exists($field, 'field_alias')) {
      $field_key = $field->field_alias;
      if ($field_key == 'unknown') {
        $field_key = $field_name;
      }
    }
    else {
      $field_key = $field_name;
    }
    $field_text = $field
      ->label() . ' (' . $field_name . ')';
    $fields[$field_key] = $field_text;
    $tokens[$field_key] = $field_name;
    $fields_name_text[$field_name] = $field_text;
  }
  $return = array();
  $return['fields'] = $fields;
  $return['tokens'] = $tokens;
  $return['fields_name_text'] = $fields_name_text;
  return $return[$type];
}