After using views to output the options of select list for term references field, I found _none options is missing from the list. In current dev module, the implementation of empty options seems not in the generic approach. I studied options_field_widget_form() which may help to inspire how to achieve this.

I writed some codes for this purpose but not sure if it is generic enough for all different cases. Please help to test and improve this and hope that module author can consider to port it into module.

Comments

jimmyko’s picture

StatusFileSize
new2.16 KB

For your reference.

// add empty option. 
// @ref options_field_widget_form(); 
$value_key = key($context['field']['columns']); 
$type = str_replace('options_', '', $context['instance']['widget']['type']); 
$multiple = $context['field']['cardinality'] > 1 || $context['field']['cardinality'] == FIELD_CARDINALITY_UNLIMITED; 
$required = $element['#required']; 
$has_value = isset($context['items'][0][$value_key]); 
$properties = _options_properties($type, $multiple, $required, $has_value); 
 
if ($properties['empty_option']) { 
  $label = theme('options_none', array('instance' => $context['instance'], 'option' => $properties['empty_option'])); 
  $options = array('_none' => $label) + $options; 
}   
jimmyko’s picture

StatusFileSize
new2.39 KB

I forgot to remove the unnecessary function in previous patch. This patch is same as before but without the unshift function.

jimmyko’s picture

Status: Active » Needs review

I change the status to "needs review" and hope anyone can help to test it. Thanks

vasike’s picture

Status: Needs review » Fixed

i see. thank you jimmyko.

your drupal API reference open my eyes. what was the issue here:
there were just a intersection of taxomomy terms array, excluding the "_none" option.
so the solution is just to be sure this option is kept in the select list.

here is the commit :http://drupalcode.org/project/term_reference_filter_by_views.git/commit/...

again, thank you Sir

p.s. @jimmyko : ofcourse your solution works, but the code it's already there, in the core.

jimmyko’s picture

Thank you vasiko. I think your solution is more elegant. Great job!

Status: Fixed » Closed (fixed)

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