Drupal overriding existing option list values

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

Answers


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.


Need Your Help

Loop through array ; find and display modulus

javascript node.js ejs

I'm retrieving records from a .json file, that I'm generating with node.js (with fs, ejs, http, request, connect modules) ;

Java Thread notify( ) vs. notifyAll()

java multithreading asynchronous synchronized monitors

I am confused a bit by Java's notify(). The following example is from a textbook.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.