link_views_argument_handler

Versions
5
link_views_argument_handler($op, &$query, $argtype, $arg = '')

Views module argument handler for link fields

Code

contributions/link/link.module, line 724

<?php
function link_views_argument_handler($op, &$query, $argtype, $arg = '') {
  if ($op == 'filter') {
    $field_name = substr($argtype['type'], 9, strrpos($argtype['type'], '_') - 9);
    $column = substr($argtype['type'], strrpos($argtype['type'], '_') + 1);
  }
  else {
    $field_name = substr($argtype, 9, strrpos($argtype, '_') - 9);
    $column = substr($argtype, strrpos($argtype, '_') + 1);
  }

  // Right now the only attribute we support in views in 'target', but
  // other attributes of the href tag could be added later.
  if ($column == 'target') {
    $attribute = $column;
    $column = 'attributes';
  }

  $field = content_fields($field_name);
  $db_info = content_database_info($field);
  $main_column = $db_info['columns'][$column];

  // The table name used here is the Views alias for the table, not the actual
  // table name.
  $table = 'node_data_'. $field['field_name'];

  switch ($op) {
    case 'summary':
      $query->ensure_table($table);
      $query->add_field($main_column['column'], $table);
      return array('field' => $table .'.'. $main_column['column']);
      break;

    case 'filter':
      $query->ensure_table($table);
      if ($column == 'attributes') {
        // Because attributes are stored serialized, our only option is to also
        // serialize the data we're searching for and use LIKE to find similar data.
        $query->add_where($table .'.'. $main_column['column'] ." LIKE '%%%s%'", serialize($attribute) . serialize($arg));
      }
      else {
        $query->add_where($table .'.'. $main_column['column'] ." = '%s'", $arg);
      }
      break;

    case 'link':
      $item = array();
      foreach ($db_info['columns'] as $column => $attributes) {
        $view_column_name = $attributes['column'];
        $item[$column] = $query->$view_column_name;
      }

      return l(content_format($field, $item, 'plain'), $arg .'/'. $query->$main_column['column'], array(), NULL, NULL, FALSE, TRUE);

    case 'sort':
      break;

    case 'title':
      $item = array(key($db_info['columns']) => $query);
      return content_format($field, $item);
      break;
  }
}
?>

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • Web page addresses and e-mail addresses turn into links automatically.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image.