I added a CCK select field to a Profile using the core Profile module. If I look at the list when editing a Profile everything is fine, but if I use the list as a Filter in a View, commas break the lines.

In Profile:
Denver, CO

In Views:
Denver
CO

I found a discussion about this when they fixed it in the Profile module. http://drupal.org/node/89459

They turned this:

...
      case 'selection':
        $options = $field->required ? array() : array('--');
        $lines = split(",[\n\r]", $field->options);
        foreach ($lines as $line) {
          if ($line = trim($line)) {
            $options[$line] = $line;
          }
        }
...

...into...

...
// line 662 - 668
      case 'selection':
        $options = $field->required ? array() : array('--');
        $lines = split("[\n\r]", $field->options);
        foreach ($lines as $line) {
          if ($line = trim($line)) {
            $options[$line] = $line;
          }
        }
...

...by removing the ',' that split the line.

Any way to stop commas from breaking lines in Views select lists chosen as Filters? Thanks.

CommentFileSizeAuthor
#1 views-420850.patch914 bytesdawehner

Comments

dawehner’s picture

StatusFileSize
new914 bytes

this exact same code is placed in views

here is the patch which does the same as your previous patch, just removes the ","

gettysburger’s picture

Awesome. Many thanks!

bverc’s picture

I also had this problem and aaplied this patch, how can I update my current views to redo the filters?

bverc’s picture

Category: support » bug

This is still an issue. If it is such a simple fix, why hasn't it made it into the views code yet?

merlinofchaos’s picture

Status: Active » Needs review

In part because this issue is not set to the 'needs review' status so it didn't show up when I was looking for patches.

merlinofchaos’s picture

Status: Needs review » Fixed

Committed.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

gettysburger’s picture

Version: 6.x-2.2 » 6.x-2.x-dev
Status: Closed (fixed) » Needs review

I upgraded to Views 2.x-dev and am still having this problem. I have emptied my cache a million times and have tried making a new view, but when I have a comma in an item in a select list in Profile, it breaks the line.

I even tried removing the comma in the profile.module file.

Any thoughts? Thanks.

dawehner’s picture

Status: Needs review » Active

This is my views_handler_field_profile_list.inc

<?php
// $Id: views_handler_field_profile_list.inc,v 1.1 2008-09-03 19:21:29 merlinofchaos Exp $
/**
 * Field handler display a profile list item.
 */
class views_handler_field_profile_list extends views_handler_field_prerender_list {
  /**
   * Break up our field into a proper list.
   */
  function render($value) {
    $field = $value->{$this->field_alias};
    $this->items[$field] = array();
    foreach (split("[,\n\r]", $field) as $item) {
      if ($item != '' && $item !== NULL) {
        $this->items[$field][] = $item;
      }
    }
    return parent::render($value);
  }
}
jbrauer’s picture

Status: Active » Reviewed & tested by the community

It looks as though this patch slipped through and didn't actually get applied as intended in July.

merlinofchaos’s picture

Interesting.

Here's the one I have:

// $Id: views_handler_field_profile_list.inc,v 1.4 2009/07/26 15:07:26 merlinofchaos Exp $
/**
 * Field handler display a profile list item.
 */
class views_handler_field_profile_list extends views_handler_field_prerender_list {
  /**
   * Break up our field into a proper list.
   */
  function pre_render($values) {
    $field = $value->{$this->field_alias};
    $this->items[$field] = array();
    foreach (split("[\n\r]", $field) as $item) {
      if ($item != '' && $item !== NULL) {
        $this->items[$field]['item'] = $item;
      }
    }
  }

  function render_item($count, $item) {
    return $item['item'];
  }

  function document_self_tokens(&$tokens) {
    $tokens['[' . $this->options['id'] . '-item' . ']'] = t('The text of the profile item.');
  }

  function add_self_tokens(&$tokens, $item) {
    $tokens['[' . $this->options['id'] . '-item' . ']'] = $item['item'];
  }
}
merlinofchaos’s picture

Status: Reviewed & tested by the community » Closed (fixed)

Doublechecked everything. This is really in, though it's not in any released code. Only 2.x and 3.x dev.

JacobSingh’s picture

Is this the twilight zone of CVS? :)

http://drupalcode.org/viewvc/drupal/contributions/modules/views/modules/...

Doesn't look like it ever made it into DRUPAL-6--2, isn't that what was meant by "Only 2.x and 3.x dev" ?

JacobSingh’s picture

Okay, never mind, the commit did go in July, not September it seems. The code looks right.

dawehner’s picture

This bug will be reappear thanks to http://drupal.org/node/675264#comment-2752976

But its no really a bug, its by design of the profile module.