You are here

function link_views_argument_handler in Link 5

Views module argument handler for link fields

1 string reference to 'link_views_argument_handler'
link_field_settings in ./link.module
Implementation of hook_field_settings().

File

./link.module, line 724
Defines simple link field types.

Code

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;
  }
}