doxd96148 2014-05-20 12:05
浏览 51

Drupal更好地暴露形式设置钩子的最小值和最大值

I have installed 'better exposed form' module on my Drupal 7 site, I created a view for commerce module catalog, and made a slider range filter on JQuery, here it is (sorry, the site is in russian language, but anyway, the essential thing is a JQueryUI slider) http://doors.ekt0.ru/. So, the question is, how to set the slider minimum and maximum possible values programatically from a hook. This is because a want to make the min and max prices be real, from the database table with product prices. Here is my code:

function zen_form_views_exposed_form_alter(&$form, $form_state) {

  $minmax = db_query('SELECT MIN(`commerce_price_amount`) AS `min`, MAX(`commerce_price_amount`) AS `max` FROM `field_data_commerce_price`')->fetchAssoc();

  $form['commerce_price_amount']['min']['#value'] = $minmax['min'];
  $form['commerce_price_amount']['max']['#value'] = $minmax['max'];
}

and here's the contents of 'commerce_price_amount' key of $form array:

[commerce_price_amount] => Array (
      [#tree] => 1
      [min] => Array (
           [#type] => textfield
           [#title] => 
           [#size] => 30
           [#default_value] => 
      )
      [max] => Array (
           [#type] => textfield
           [#title] => And
           [#size] => 30
           [#default_value] => 
      )
)

So, as we see here, the only array key that looks like what I need is #default_value, but it's not actually the one, it doesn't make any visible changes to the form, and I also tried #value key (as on the code), but it sets default slider range values, just moving the knobs, not making minimum and maximum values. So the question is, how to do it, and the second question is that perhaps, there is any setting in the module to set that min and max values automatically (I coudn't manage to find anything in the settings). Thanks in advance!

  • 写回答

1条回答 默认 最新

  • dongmi1864 2014-09-29 12:05
    关注

    BEF module add these options as javascript options, so you can use hook_js_alter() to override it.

    /**
     * Implements hook_js_alter().
     */
    function MODULE_js_alter(&$javascript) {
      $settings = $javascript['settings']['data'];
    
      foreach ($settings as $key => $value) {
        if (isset($settings[$key]['better_exposed_filters']['slider_options']['commerce_price_amount']['max'])) {
          $settings[$key]['better_exposed_filters']['slider_options']['commerce_price_amount']['max'] = 1000;
        }
      }
    
      $javascript['settings']['data'] = $settings;
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法