Hello,

Using Views 7.x-3.0-alpha1, I'm not getting a sort handler from a computed field that I created with 'longtext', 'Sortable'.

I've never used this before, so I may simply be misunderstanding something.

Steps to reproduce:

Content type with a computed field. Code produces a chunk of text.

Storage Settings:
- Data Type: longtext
- Data Length: 255
- Sortable: yes

And then under Views, I'd expect to see this field under Sort criteria, but it's not there.

Comments

Moonshine’s picture

Status: Active » Closed (works as designed)

longtext, text (and blob) db fields are all for large data sets and core's Field module precludes them from being used as a sort option in Views. In you case if you only need up to a 255 length you're just fine using a Varchar 255 which will show as a sort option in views.

From the Field code:

    // Identify likely filters and arguments for each column based on field type.
    switch ($attributes['type']) {
      case 'int':
      case 'mediumint':
      case 'tinyint':
      case 'bigint':
      case 'serial':
      case 'numeric':
      case 'float':
        $filter = 'views_handler_filter_numeric';
        $argument = 'views_handler_argument_numeric';
        $sort = 'views_handler_sort';
        break;
      case 'text':
      case 'blob':
        // It does not make sense to sort by blob or text.
        $allow_sort = FALSE;
      default:
        $filter = 'views_handler_filter_string';
        $argument = 'views_handler_argument_string';
        $sort = 'views_handler_sort';
        break;
    }