Drupal 暴露日期过滤器:从选择中删除“-Year”

Posted

技术标签:

【中文标题】Drupal 暴露日期过滤器:从选择中删除“-Year”【英文标题】:Drupal exposed date filter: remove "-Year" from select 【发布时间】:2010-01-06 23:16:59 【问题描述】:

正如标题所说,我不明白为什么“-Year”被添加到我暴露的过滤器选择框的顶部。我需要做什么才能让它消失?

【问题讨论】:

【参考方案1】:

在配置日期过滤器时,在“绝对值”下拉列表中选择年份。然后将显示该年份而不是 -Year。我怀疑,除非您对源代码进行一些更改/添加,否则您实际上可以从暴露的选择框中删除 -Year。

【讨论】:

问题是我们希望选择当前年份。我终于找到了解决办法,我会在下面贴出来。【参考方案2】:

找到了解决方案,这很愚蠢。

我最终把它放在了一个自定义模块中,最终删除了标签并根据数据库中的数据设置了显示的年数:

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";
    

【讨论】:

以上是关于Drupal 暴露日期过滤器:从选择中删除“-Year”的主要内容,如果未能解决你的问题,请参考以下文章