dongying195959 2011-12-01 05:32
浏览 19
已采纳

Drupal覆盖现有选项列表值

Currently entityreference do not support filtering (via views like references). I have to filter the returned result of option lists manually via hook_form_alter.

$new_options = array(1 => 'One', 2 => 'Two', 3 => 'Three'); // while old values without filtering results in 10 items
$form['field_entityreference'][$lang]['#options'] = $new_options;

This works fine at front end, but when I viewed via dsm($form);, the old values are still there.

A couple of tries to no avail:

   if ($old_options = $form['field_entityreference'][$lang]['#options']) {
     foreach ($old_options as $key => $old_option) {
       unset($form['field_entityreference'][$lang]['#options'][$key]);
     }
  }

Or even unset($form['field_entityreference'][$lang]['#options']); With array_diff_key also the old options are still held there.

The front end is just fine, only new options shown, but I need to exclude the unneeded from the source, because rules always evaluates to true when they are not totally removed which is unexpected.

How do you remove lingering old values, so that only the new values are held even in the backend?

The helpful function is not there yet: http://drupal.org/node/1085704. Any hint would be very much appreciated. Thanks

  • 写回答

1条回答 默认 最新

  • doucheng1884 2011-12-01 09:15
    关注

    Sorry to bother. This is a matter of dsm() placement. Actually all is good. The problem is dsm(); was always placed prior to any overrides, and drupal still read the old values. Placing dsm(); after the overrides displays the expected results, what a struggle :). Rules is another story.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度