line 1185 reads:

$options[''] = $blank;

This results in the first actual term in the options dropdown to be overwritten with $blank.

Assigning $blank to element 0 explicilty fixes it:

$options[0] = $blank;

You could also use:

$options[] = $blank;

Comments

harry slaughter’s picture

Priority: Normal » Critical

I'm marking this critical as it does break taxonomy, although not in a severe way.

This problem may only manifest in view filters.

To see the problem, set up a site using 5.6, generate a *single select* taxonomy category. create a view that has an exposed taxonomy filter for this category.

Note in the exposed filter that the top term in this category is replaced with '- None -'.

harry slaughter’s picture

StatusFileSize
new12.4 KB
new12.4 KB

If this image uploads, notice the first term in the taxonomy filter is "Two" where it should be "One".

btully’s picture

subscribe

zeta ζ’s picture

Could you mark this needs review? I know it’s only one line, but wouldn’t all those eager reviewers find a patch useful?

harry slaughter’s picture

Version: 5.6 » 5.7
Status: Active » Needs review
StatusFileSize
new596 bytes

Good suggestion. Here's a patch against 5.7

zeta ζ’s picture

I’m guessing this is by design, as the row added here is not a term, so should be treated differently. It is not over-writing any other term as there are none to over-write, and;

$a = array();
$a[''] = 'blank';

$a[] = 'One';
$a[] = 'Two';
$a[] = 'Three';
print_r($a);
 

gives;-

Array
(
    [] => blank
    [0] => One
    [1] => Two
    [2] => Three
)

I can only guess that views is not expecting a non-integer key, or is not handling it properly.

I don’t think that passing a 0 meaning no label to this function, is ideal – null would be better – and $blank is not an ideal name for this argument: if($blank) {...} doesn’t convey the logic of the code, in fact, the opposite.

Using '' as the key is a little obscure if this array is being used elsewhere: 'default' might be more explicit, but changing this might break other code that relies on ''. ‘Magic’ values are always difficult.

If the maintainers of taxonomy are happy to change the keys, and this fixes the issue – then fine, but I think this is caused by views.

drumm’s picture

Status: Needs review » Closed (works as designed)

Agreed with above review. Please re-open against either 6.0 or a contributed module if the problem persists.

btully’s picture

we're not going to 6.0 any time soon unfortunately, so is the patch our only solution? It seems strange that the key would be changed just for the sake of changing it without an explanation of what the benefits are, do I doubt this is the case. However, changing the key back to $options[] = $blank fixes the issue with Views and doesn't appear to break anything else. Can someone explain why the key was changed to $options[''] = $blank and what I might be missing as having broken since changing it back using the patch?

Many thanks in advance and thanks to Harry for this patch.