You are here

function _views_send_get_fields_and_tokens in Views Send 8

Same name and namespace in other branches
  1. 6 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_config_form in ./views_send.module
Implements the form for the "configure" step.

File

./views_send.module, line 1018
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 FALSE;
  }
  $fields = array();
  $tokens = array();
  $fields_name_text = array();
  $enable_excluded_fields = $view->field['views_send_bulk_form']->options['enable_excluded_fields'];
  foreach ($view->field as $field_name => $field) {

    // Ignore Views Send field(s).
    if ($field instanceof ViewsSend) {
      continue;
    }
    elseif (isset($field->options['exclude']) && $field->options['exclude']) {

      // If enable_excluded_fields is false, excluded fields should not be available.
      if (!$enable_excluded_fields) {
        continue;
      }
    }
    if (!empty($field->field)) {
      $field_key = $field->field;
    }
    elseif (property_exists($field, 'field_alias')) {
      $field_key = $field->field_alias;
      if ($field_key == 'unknown') {
        $field_key = $field_name;
      }
    }
    else {
      $field_key = $field_name;
    }

    // Add field position to ensure unique keys.
    $field_key .= '_pos_' . $field->position;
    $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];
}