You are here

viewreference.module in View reference 6.3

Defines a field type for referencing a view from a node.

File

viewreference.module
View source
<?php

/**
 * @file
 * Defines a field type for referencing a view from a node.
 */

/**
 * Implementation of hook_menu().
 */
function viewreference_menu() {
  $items = array();
  $items['viewreference/autocomplete'] = array(
    'title' => 'viewreference autocomplete',
    'page callback' => 'viewreference_autocomplete',
    'access arguments' => array(
      'access content',
    ),
    'type' => MENU_CALLBACK,
  );
  return $items;
}

/**
 * Implementation of hook_theme().
 */
function viewreference_theme() {
  return array(
    'viewreference_display_title' => array(
      'arguments' => array(
        'view' => NULL,
        'view_name' => NULL,
        'display_name' => NULL,
        'append_id' => FALSE,
      ),
    ),
    'viewreference_select' => array(
      'arguments' => array(
        'element' => NULL,
      ),
    ),
    'viewreference_autocomplete' => array(
      'arguments' => array(
        'element' => NULL,
      ),
    ),
    'viewreference_formatter_default' => array(
      'arguments' => array(
        'element',
      ),
    ),
    'viewreference_formatter_full' => array(
      'arguments' => array(
        'element',
      ),
    ),
    'viewreference_formatter_plain' => array(
      'arguments' => array(
        'element',
      ),
    ),
    'viewreference_formatter_link' => array(
      'arguments' => array(
        'element',
      ),
    ),
    'viewreference_formatter_path' => array(
      'arguments' => array(
        'element',
      ),
    ),
  );
}

/**
 * Implementation of hook_field_info().
 *
 * Here we indicate that the content module will use its default
 * handling for the view of this field.
 *
 * Callbacks can be omitted if default handing is used.
 * They're included here just so this module can be used
 * as an example for custom modules that might do things
 * differently.
 */
function viewreference_field_info() {
  return array(
    'viewreference' => array(
      'label' => t('View reference'),
      'description' => t('Reference a views display from the views module.'),
      'callbacks' => array(
        'tables' => CONTENT_CALLBACK_DEFAULT,
        'arguments' => CONTENT_CALLBACK_DEFAULT,
      ),
    ),
  );
}

/**
 * Implementation of hook_field_settings().
 */
function viewreference_field_settings($op, $field) {
  switch ($op) {
    case 'form':
      $form = array();
      $form['referenceable_views'] = array(
        '#type' => 'checkboxes',
        '#title' => t('Views that can be referenced'),
        '#description' => t('Select the views that can be referenced. If no views are selected, then all the views will be available.'),
        '#multiple' => TRUE,
        '#default_value' => is_array($field['referenceable_views']) ? $field['referenceable_views'] : array(),
        '#options' => viewreference_get_views($field['append_id']),
      );
      $form['arguments'] = array(
        '#type' => 'fieldset',
        '#title' => t('Arguments'),
        '#collapsible' => TRUE,
        '#collapsed' => $field['dsv_arguments'] || $field['php_arguments'] ? FALSE : TRUE,
        '#description' => t('Enabling the following options will provide an input field for passing arguments to the view.'),
      );
      $form['arguments']['dsv_arguments'] = array(
        '#type' => 'checkbox',
        '#title' => t('Allow delimiter seperated values.'),
        '#default_value' => isset($field['dsv_arguments']) ? $field['dsv_arguments'] : 0,
        '#description' => t('Users can provide a list of arguments seperated by a delimiter. e.g: <em>term_1/term_2</em>'),
      );
      $form['arguments']['php_arguments'] = array(
        '#type' => 'checkbox',
        '#title' => t('Allow PHP code.'),
        '#default_value' => isset($field['php_arguments']) ? $field['php_arguments'] : 0,
        '#description' => t('Users can insert PHP code to generate the list of arguments. e.g: <em>term_1/&lt;?php print "term_x/term_y"; ?&gt;/term_2</em>'),
      );
      $form['arguments']['delimiter'] = array(
        '#type' => 'textfield',
        '#title' => t('Delimiter'),
        '#default_value' => !empty($field['delimiter']) ? $field['delimiter'] : '/',
        '#size' => 3,
        '#maxlength' => 30,
        '#required' => TRUE,
      );
      $row_range = range(0, 10);
      unset($row_range[0]);
      $form['arguments']['rows'] = array(
        '#type' => 'select',
        '#title' => t('Number of rows in argument field'),
        '#default_value' => isset($field['rows']) ? $field['rows'] : 1,
        '#options' => $row_range,
        '#description' => t('Set as 1 for textfield, or larger values for textarea (may be easier to write PHP with a textarea)'),
        '#required' => TRUE,
      );
      $form['append_id'] = array(
        '#type' => 'checkbox',
        '#title' => t('Append unique ID in lists.'),
        '#default_value' => isset($field['append_id']) ? $field['append_id'] : 0,
        '#description' => t('It is possible for views displays to have the same title, this option will append [view:view_display_n] in lists used by this field to disambiguate the options.'),
      );
      return $form;
    case 'save':
      $settings = array(
        'referenceable_views',
        'dsv_arguments',
        'php_arguments',
        'delimiter',
        'rows',
        'append_id',
      );
      return $settings;
    case 'database columns':
      $columns = array(
        'view_id' => array(
          'type' => 'varchar',
          'length' => '255',
          'default' => NULL,
          'not null' => FALSE,
        ),
        'arguments' => array(
          'type' => 'text',
          'size' => 'big',
        ),
      );
      return $columns;
    case 'views data':
      $data = content_views_field_views_data($field);
      $db_info = content_database_info($field);
      $table_alias = content_views_tablename($field);

      // Swap the filter handler to the 'in' operator.
      $data[$table_alias][$field['field_name'] . '_view_id']['filter']['handler'] = 'views_handler_filter_many_to_one_content';
      return $data;
  }
}

/**
 * Implementation of hook_field().
 */
function viewreference_field($op, &$node, $field, &$items, $teaser, $page) {
  switch ($op) {
    case 'validate':
      $views = viewreference_get_views($field['append_id'], $field['referenceable_views']);
      foreach ($items as $delta => $item) {
        if (is_array($item) && !empty($item['error_field'])) {
          $error_field = $item['error_field'];
          unset($item['error_field']);
          if (!empty($item['view_id'])) {
            if (!in_array($item['view_id'], array_keys($views))) {
              form_set_error($error_field, t("%name : This view can't be referenced.", array(
                '%name' => t($field['widget']['label']),
              )));
            }
          }
        }
      }
      return $items;
  }
}

/**
 * Implementation of hook_content_is_empty().
 */
function viewreference_content_is_empty($item, $field) {
  return empty($item['view_id']);
}

/**
 * Implementation of hook_field_formatter_info().
 */
function viewreference_field_formatter_info() {
  return array(
    'default' => array(
      'label' => t('Default (view)'),
      'field types' => array(
        'viewreference',
      ),
      'multiple values' => CONTENT_HANDLE_CORE,
    ),
    'full' => array(
      'label' => t('Full (title and view)'),
      'field types' => array(
        'viewreference',
      ),
      'multiple values' => CONTENT_HANDLE_CORE,
    ),
    'plain' => array(
      'label' => t('Title (no link)'),
      'field types' => array(
        'viewreference',
      ),
      'multiple values' => CONTENT_HANDLE_CORE,
    ),
    'link' => array(
      'label' => t('Title (link)'),
      'field types' => array(
        'viewreference',
      ),
      'multiple values' => CONTENT_HANDLE_CORE,
    ),
    'path' => array(
      'label' => t('Path'),
      'field types' => array(
        'viewreference',
      ),
      'multiple values' => CONTENT_HANDLE_CORE,
    ),
  );
}

/**
 * Helper function for stock theme functions.
 *
 * @param $element
 *   The field element.
 * @param $params
 *   An array of special features needed to be built:
 *     'embed' - The $view->preview() of the view display
 *     'title' - The display title of the view display
 *     'link' - A link to the view display, or the title if link not available.
 * @return
 *   The view object.
 */
function viewreference_get_view($element, $params = array()) {
  if (!empty($element['#item']['view_id'])) {
    $view_id_parts = explode(":", $element['#item']['view_id']);
    $view['name'] = $view_id_parts[0];
    $view['display'] = $view_id_parts[1];
    $view['view'] = views_get_view($view['name']);
    if ($view['view'] && $view['view']
      ->access($view['display'])) {
      if (in_array('embed', $params)) {
        $view['args'] = viewreference_get_element_args($element);
        $view['embed'] = $view['view']
          ->preview($view['display'], $view['args']);
      }
      if (in_array('title', $params) || in_array('link', $params)) {
        $view['title'] = theme('viewreference_display_title', $view['view'], $view['name'], $view['display']);
        if (in_array('link', $params)) {
          if (isset($view['view']->display[$view['display']]->display_options['path']) && !$view['view']->disabled) {
            $view['args'] = $view['args'] ? $view['args'] : viewreference_get_element_args($element);
            $view['url_args'] = implode("/", $view['args']);
            $view['path'] = $view['view']->display[$view['display']]->display_options['path'];
            if ($view['url_args']) {
              $view['path'] .= "/" . $view['url_args'];
            }
            $view['link'] .= l($view['title'], $view['view']
              ->get_url($view['args'], $view['path']));
          }
          else {
            $view['link'] .= $view['title'];
          }
        }
      }
      return $view;
    }
  }
}

/**
 * Theme function for 'default' viewreference field formatter.
 */
function theme_viewreference_formatter_default($element) {
  $output = '';
  if ($view = viewreference_get_view($element, array(
    'embed',
  ))) {
    $output .= $view['embed'];
  }
  return $output;
}

/**
 * Theme function for 'full' viewreference field formatter.
 */
function theme_viewreference_formatter_full($element) {
  $output = '';
  if ($view = viewreference_get_view($element, array(
    'title',
    'embed',
  ))) {
    $output .= '<h3 class="title viewreference-title">' . $view['title'] . '</h3>';
    $output .= $view['embed'];
  }
  return $output;
}

/**
 * Theme function for 'plain' viewreference field formatter.
 */
function theme_viewreference_formatter_plain($element) {
  $output = '';
  if ($view = viewreference_get_view($element, array(
    'title',
  ))) {
    $output .= $view['title'];
  }
  return $output;
}

/**
 * Theme function for 'link' viewreference field formatter.
 */
function theme_viewreference_formatter_link($element) {
  $output = '';
  if ($view = viewreference_get_view($element, array(
    'link',
  ))) {
    $output .= $view['link'];
  }
  return $output;
}

/**
 * Theme function for 'path' viewreference field formatter.
 */
function theme_viewreference_formatter_path($element) {
  $output = '';
  if ($view = viewreference_get_view($element, array(
    'link',
  ))) {
    $output .= isset($view['path']) ? $view['path'] : $view['link'];
  }
  return $output;
}

/**
 * Implementation of hook_widget_info().
 *
 * We need custom handling of multiple values for the viewreference_select
 * widget because we need to combine them into a options list rather
 * than display multiple elements.
 *
 * We will use the content module's default handling for default value.
 *
 * Callbacks can be omitted if default handing is used.
 * They're included here just so this module can be used
 * as an example for custom modules that might do things
 * differently.
 */
function viewreference_widget_info() {
  return array(
    'viewreference_select' => array(
      'label' => t('Select list'),
      'field types' => array(
        'viewreference',
      ),
      'multiple values' => CONTENT_HANDLE_CORE,
      'callbacks' => array(
        'default value' => CONTENT_CALLBACK_DEFAULT,
      ),
    ),
    'viewreference_autocomplete' => array(
      'label' => t('Autocomplete text field'),
      'field types' => array(
        'viewreference',
      ),
      'multiple values' => CONTENT_HANDLE_CORE,
      'callbacks' => array(
        'default value' => CONTENT_CALLBACK_DEFAULT,
      ),
    ),
  );
}

/**
 * Implementation of FAPI hook_elements().
 *
 * Any FAPI callbacks needed for individual widgets can be declared here,
 * and the element will be passed to those callbacks for processing.
 *
 * Drupal will automatically theme the element using a theme with
 * the same name as the hook_elements key.
 *
 * Autocomplete_path is not used by text_widget but other widgets can use it
 * (see viewreference and userreference).
 */
function viewreference_elements() {
  return array(
    'viewreference_select' => array(
      '#input' => TRUE,
      '#columns' => array(
        'uid',
      ),
      '#delta' => 0,
      '#process' => array(
        'viewreference_select_process',
      ),
    ),
    'viewreference_autocomplete' => array(
      '#input' => TRUE,
      '#columns' => array(
        'name',
      ),
      '#delta' => 0,
      '#process' => array(
        'viewreference_autocomplete_process',
      ),
      '#autocomplete_path' => FALSE,
    ),
  );
}

/**
 * Implementation of hook_widget().
 *
 * Attach a single form element to the form. It will be built out and
 * validated in the callback(s) listed in hook_elements. We build it
 * out in the callbacks rather than here in hook_widget so it can be
 * plugged into any module that can provide it with valid
 * $field information.
 *
 * Content module will set the weight, field name and delta values
 * for each form element. This is a change from earlier CCK versions
 * where the widget managed its own multiple values.
 *
 * If there are multiple values for this field, the content module will
 * call this function as many times as needed.
 *
 * @param $form
 *   the entire form array, $form['#node'] holds node information
 * @param $form_state
 *   the form_state, $form_state['values'][$field['field_name']]
 *   holds the field's form values.
 * @param $field
 *   the field array
 * @param $items
 *   array of default values for this field
 * @param $delta
 *   the order of this item in the array of subelements (0, 1, 2, etc)
 *
 * @return
 *   the form item for a single element for this field
 */
function viewreference_widget(&$form, &$form_state, $field, $items, $delta = 0) {
  switch ($field['widget']['type']) {
    case 'viewreference_select':
      $element = array(
        '#type' => 'viewreference_select',
        '#default_value' => isset($items[$delta]) ? $items[$delta] : NULL,
      );
      break;
    case 'viewreference_autocomplete':
      $element = array(
        '#type' => 'viewreference_autocomplete',
        '#default_value' => isset($items[$delta]) ? $items[$delta] : NULL,
        '#value_callback' => 'viewreference_autocomplete_value',
      );
      break;
  }
  return $element;
}

/**
 * Value for a viewreference autocomplete element.
 *
 * Substitute in the view title for the internal view id.
 */
function viewreference_autocomplete_value($element, $edit = FALSE) {
  $field_key = $element['#columns'][0];
  $args_key = $element['#columns'][1];
  if (!empty($element['#default_value'][$field_key])) {
    $field = content_fields($element['#field_name']);
    $views = viewreference_get_views(TRUE, array(
      $element['#default_value'][$field_key],
    ));
    $value = $views[$element['#default_value'][$field_key]];
    return array(
      $field_key => $value,
      $args_key => $element['#default_value'][$args_key],
    );
  }
  return array(
    $field_key => NULL,
    $args_key => $element['#default_value'][$args_key],
  );
}

/**
 * Process an individual element.
 *
 * Build the form element. When creating a form using FAPI #process,
 * note that $element['#value'] is already set.
 *
 * The $fields array is in $form['#field_info'][$element['#field_name']].
 */
function viewreference_select_process($element, $edit, $form_state, $form) {
  $field = $form['#field_info'][$element['#field_name']];
  $element[$element['#columns'][0]] = array(
    '#type' => 'select',
    '#multiple' => 0,
    '#options' => viewreference_allowed_values($field),
    '#default_value' => isset($element['#value'][$element['#columns'][0]]) ? $element['#value'][$element['#columns'][0]] : '',
    '#element_validate' => array(
      'viewreference_select_validate',
    ),
    '#prefix' => t('<div class="viewreference-wrapper" id="viewreference-!field_id">', array(
      "!field_id" => str_replace('_', '-', $element['#field_name']) . '-' . $element['#delta'],
    )),
    // localized for customisations
    // The following values were set by the content module and need
    // to be passed down to the nested element.
    '#field_name' => $element['#field_name'],
    '#delta' => $element['#delta'],
    '#columns' => $element['#columns'],
    '#title' => $element['#title'],
    '#required' => $element['#required'],
    '#description' => $element['#description'],
  );
  if ($field['dsv_arguments'] == 1 || $field['php_arguments'] == 1) {
    if ($field['rows'] == 1) {
      $args_widget = 'textfield';
    }
    else {
      $args_widget = 'textarea';
    }
    $element[$element['#columns'][1]] = array(
      '#type' => $args_widget,
      '#default_value' => isset($element['#value'][$element['#columns'][1]]) ? $element['#value'][$element['#columns'][1]] : '',
      '#element_validate' => array(
        'viewreference_arguments_validate',
      ),
      '#title' => $element['#title'] . ' ' . t('arguments'),
      '#suffix' => t('</div>'),
      '#rows' => $field['rows'],
      // The following values were set by the content module and need
      // to be passed down to the nested element.
      '#field_name' => $element['#field_name'] . t(" arguments"),
      '#delta' => $element['#delta'],
      '#columns' => $element['#columns'],
      '#required' => $element['#required'],
      '#description' => $element['#description'],
    );
  }
  else {
    $element[$element['#columns'][0]]['#suffix'] = t('</div>');
  }
  return $element;
}

/**
 * Process an individual element.
 *
 * Build the form element. When creating a form using FAPI #process,
 * note that $element['#value'] is already set.
 *
 */
function viewreference_autocomplete_process($element, $edit, $form_state, $form) {
  $field = $form['#field_info'][$element['#field_name']];
  $element[$element['#columns'][0]] = array(
    '#type' => 'text_textfield',
    '#default_value' => isset($element['#value']) ? $element['#value'] : '',
    '#autocomplete_path' => 'viewreference/autocomplete/' . $element['#field_name'],
    '#element_validate' => array(
      'viewreference_autocomplete_validate',
    ),
    '#prefix' => t('<div class="viewreference-wrapper" id="viewreference-!field_id">', array(
      "!field_id" => str_replace('_', '-', $element['#field_name']) . '-' . $element['#delta'],
    )),
    // localized for customisations
    // The following values were set by the content module and need
    // to be passed down to the nested element.
    '#field_name' => $element['#field_name'],
    '#delta' => $element['#delta'],
    '#columns' => $element['#columns'],
    '#title' => $element['#title'],
    '#required' => $element['#required'],
    '#description' => $element['#description'],
  );
  if ($field['dsv_arguments'] == 1 || $field['php_arguments'] == 1) {
    if ($field['rows'] == 1) {
      $args_widget = 'textfield';
    }
    else {
      $args_widget = 'textarea';
    }
    $element[$element['#columns'][1]] = array(
      '#type' => $args_widget,
      '#default_value' => isset($element['#value'][$element['#columns'][1]]) ? $element['#value'][$element['#columns'][1]] : '',
      '#element_validate' => array(
        'viewreference_arguments_validate',
      ),
      '#title' => $element['#title'] . ' ' . t('arguments'),
      '#suffix' => t('</div>'),
      '#rows' => $field['rows'],
      // The following values were set by the content module and need
      // to be passed down to the nested element.
      '#field_name' => $element['#field_name'] . t(" arguments"),
      '#delta' => $element['#delta'],
      '#columns' => $element['#columns'],
      '#required' => $element['#required'],
      '#description' => $element['#description'],
    );
  }
  else {
    $element[$element['#columns'][0]]['#suffix'] = t('</div>');
  }
  return $element;
}

/**
 * Validate an autocomplete element.
 *
 * Remove the wrapper layer and set the right element's value.
 */
function viewreference_autocomplete_validate($element, &$form_state) {
  $field_name = $element['#field_name'];
  $field = content_fields($field_name);
  $field_key = $element['#columns'][0];
  $value = $element['#value'][$field_key];
  $new_value = NULL;
  if (!empty($value)) {
    $regex = '/' . '(.*).*?' . '(\\[)' . '((?:[a-z][a-z0-9_]*))' . '(:)' . '((?:[a-z][a-z0-9_]*))' . '(\\])' . '/is';

    // End of string
    preg_match($regex, $value, $matches);
    if (!empty($matches)) {
      $new_value = $matches[3] . ':' . $matches[5];
      $allowed = viewreference_get_views(FALSE, $field['settings']['referenceable_views']);
      if (!isset($allowed[$new_value])) {
        form_error($element, t('%name: View display %value cannot be referenced.', array(
          '%name' => $element[$field_key]['#title'],
          '%value' => $new_value,
        )));
      }
    }
    else {
      form_error($element, t('%name: The value %value is in an unexpected format.  Expecting: %format', array(
        '%name' => $element[$field_key]['#title'],
        '%value' => $value,
        '%format' => '<em>View title [view:display_n]</em>',
      )));
    }
  }
  form_set_value($element, $new_value, $form_state);
}

/**
 * Implementation of hook_allowed_values().
 */
function viewreference_allowed_values($field) {
  $options = viewreference_get_views($field['append_id'], $field['referenceable_views']);
  if (!$field['required']) {
    $options = array(
      0 => '<' . t('none') . '>',
    ) + $options;
  }
  return $options;
}

/**
 * Retrieve a pipe delimited string of autocomplete suggestions.
 */
function viewreference_autocomplete($field_name, $string = '') {

  // If the request has a '/' in the search text, then the menu system will have
  // split it into multiple arguments, recover the intended $string.
  $args = func_get_args();

  // Shift off the $field_name argument.
  array_shift($args);
  $string = implode('/', $args);
  $field = content_fields($field_name);
  $matches = viewreference_get_views($field['append_id'], $field['referenceable_views'], FALSE, $string, FALSE, TRUE);
  drupal_json($matches);
}

/**
 * FAPI theme for an individual elements.
 *
 * The textfield or select is already rendered by the
 * textfield or select themes and the html output
 * lives in $element['#children']. Override this theme to
 * make custom changes to the output.
 *
 * $element['#field_name'] contains the field name
 * $element['#delta]  is the position of this element in the group
 */
function theme_viewreference_select($element) {
  return $element['#children'];
}
function theme_viewreference_autocomplete($element) {
  return $element['#children'];
}

/**
 * Get an array of views.
 *
 * @param $append_id
 *   Whether to append the id to the returned display names.
 * @param $filter
 *   A list of IDs in the format view_name:display_key to restrict results by.
 * @param $full
 *   If TRUE will return all the data, rather than just the title.
 * @param $string
 *   String to match against the title to filter results by.
 * @param $exact_string
 *   If TRUE the $string parameter must match exactly.
 * @param $long_key
 *   If TRUE will key array by the title and ID, not just the ID.
 *
 * @return
 *   The array of views.
 */
function viewreference_get_views($append_id = FALSE, $filter = NULL, $full = FALSE, $string = '', $exact_string = FALSE, $long_key = FALSE) {
  $views = array();
  $loaded_views = views_get_all_views();
  $filter = $filter ? array_filter($filter) : NULL;
  foreach ((array) $loaded_views as $view_name => $view) {
    foreach ((array) $view->display as $display_key => $display) {

      // Skip this one if it's a 'default' view.
      if ($display_key != 'default') {
        $id = $view_name . ":" . $display_key;

        // Skip this one if it's not 'allowed'.
        if (empty($filter) || in_array($id, $filter)) {

          // Get display title.
          $display_title = theme('viewreference_display_title', $view, $view_name, $display_key, $append_id);

          // Determine whether and what to return.
          $key = $long_key ? $display_title . ($append_id ? '' : ' [' . $id . ']') : $id;
          if ($string) {
            if (!$exact_string && (stripos($display_title, $string) !== FALSE || stripos($key, $string) !== FALSE)) {
              $views[$key] = $full ? $display : $display_title;
            }
            else {
              if ($display_title == $string) {
                $views[$key] = $full ? $display : $display_title;
              }
            }
          }
          else {
            $views[$key] = $full ? $display : $display_title;
          }
        }
      }
    }
  }
  return $views;
}

/**
 * Theme the display title for this view display.
 *
 * @param $view
 *  The view object.
 * @param $view_name
 *  The name of the view.
 * @param $display_name
 *  The name of the display to use.
 * @param $append_id
 *  Boolean indicating whether to append a unique id.
 * @return
 *  The display title of this views display.
 */
function theme_viewreference_display_title($view, $view_name, $display_name, $append_id = FALSE) {
  $view
    ->set_display($display_name);
  $display_title = $view
    ->get_title();
  if (!$display_title) {

    // No title, we have to construct a title.
    $display_title = ucfirst($view_name) . " " . strtolower($view->display[$display_name]->display_title);
  }
  if ($append_id) {

    // Append ID for disambiguation in forms (views displays can have the same title).
    $display_title .= " [" . $view_name . ':' . $display_name . "]";
  }
  return $display_title;
}

/**
 * Convert arguments text field entry to an array of arguments.
 */
function viewreference_get_element_args($element) {
  $string =& $element['#item']['arguments'];
  $settings = unserialize(db_result(db_query("SELECT global_settings FROM {content_node_field} WHERE field_name = '%s'", $element['#field_name'])));
  $delimiter =& $settings['delimiter'];
  $dsv_arguments =& $settings['dsv_arguments'];
  $php_arguments =& $settings['php_arguments'];
  $arguments = '';
  $args = array();
  if ($php_arguments) {
    $variables = array(
      'node' => $element['#node'],
    );
    $arguments = viewreference_eval($string, $variables);
  }
  else {
    if ($dsv_arguments) {
      $arguments = $string;
    }
  }
  if ($arguments) {
    $args = explode($delimiter, $arguments);
    foreach ($args as $k => $v) {
      $args[$k] = trim($v);
    }
  }
  return $args;
}

/**
 * Evaluate the code, whilst selecting what variables will be available in the PHP.
 */
function viewreference_eval($code, $variables = array()) {
  global $theme_path, $theme_info, $conf;

  // Store current theme path.
  $old_theme_path = $theme_path;

  // Restore theme_path to the theme, as long as drupal_eval() executes,
  // so code evaluted will not see the caller module as the current theme.
  // If theme info is not initialized get the path from theme_default.
  if (!isset($theme_info)) {
    $theme_path = drupal_get_path('theme', $conf['theme_default']);
  }
  else {
    $theme_path = dirname($theme_info->filename);
  }
  foreach ((array) $variables as $key => $value) {
    ${$key} = $value;
  }
  ob_start();
  print eval('?>' . $code);
  $output = ob_get_contents();
  ob_end_clean();

  // Recover original theme path.
  $theme_path = $old_theme_path;
  return $output;
}

Functions

Namesort descending Description
theme_viewreference_autocomplete
theme_viewreference_display_title Theme the display title for this view display.
theme_viewreference_formatter_default Theme function for 'default' viewreference field formatter.
theme_viewreference_formatter_full Theme function for 'full' viewreference field formatter.
theme_viewreference_formatter_link Theme function for 'link' viewreference field formatter.
theme_viewreference_formatter_path Theme function for 'path' viewreference field formatter.
theme_viewreference_formatter_plain Theme function for 'plain' viewreference field formatter.
theme_viewreference_select FAPI theme for an individual elements.
viewreference_allowed_values Implementation of hook_allowed_values().
viewreference_autocomplete Retrieve a pipe delimited string of autocomplete suggestions.
viewreference_autocomplete_process Process an individual element.
viewreference_autocomplete_validate Validate an autocomplete element.
viewreference_autocomplete_value Value for a viewreference autocomplete element.
viewreference_content_is_empty Implementation of hook_content_is_empty().
viewreference_elements Implementation of FAPI hook_elements().
viewreference_eval Evaluate the code, whilst selecting what variables will be available in the PHP.
viewreference_field Implementation of hook_field().
viewreference_field_formatter_info Implementation of hook_field_formatter_info().
viewreference_field_info Implementation of hook_field_info().
viewreference_field_settings Implementation of hook_field_settings().
viewreference_get_element_args Convert arguments text field entry to an array of arguments.
viewreference_get_view Helper function for stock theme functions.
viewreference_get_views Get an array of views.
viewreference_menu Implementation of hook_menu().
viewreference_select_process Process an individual element.
viewreference_theme Implementation of hook_theme().
viewreference_widget Implementation of hook_widget().
viewreference_widget_info Implementation of hook_widget_info().