tags:

views:

513

answers:

2

Just what the title says, I can't figure out why "-Year" is being added to the top of my exposed filter select box. What do I need to do to make it go away?

A: 

Select a year in the "Absolute value" dropdown when configuring your Date filter. That year will then be displayed instead of -Year. I doubt though you can actually remove -Year from the exposed select box unless you make some source code changes/additions.

Owen
The problem is that we want the current year to be selected. I finally found a solution, I'll post it below.
Karl
A: 

Found a solution to this, and it's pretty stupid.

I ended up putting this in a custom module, and ended up both removing the label and also setting the number of years displayed based on the data that's in the database:

function modulename_form_views_exposed_form_alter(&$form, $form_state) {
    if($form['#id'] == 'theformid') {
        // Remove the label as the first element from the date select
        $form['date_filter']['value']['#date_label_position'] = 'none';

        // Find the minimum year from all of the published news nodes
        $date = db_fetch_array(
                    db_query("
                            SELECT YEAR(MIN(d.field_date_value)) as 'min'
                            FROM {content_field_date} d
                            INNER JOIN {node} n
                                ON n.nid = d.nid
                            WHERE n.type = 'news' AND n.status = 1")
                );

        // Set the new year range in the filter
        $new_min = date('Y') - $date['min'];
        $form['date_filter']['value']['#date_year_range'] = "-$new_min:+0";
    }
}
Karl