The relationship delta in Views helps you to link a specific referenced node. but it only has 1 to 10 options. I want to increase the delta limit, so let’s hack the CCK module. Yes, the CCK module instead of the Views module. =P
Open cck/includes/views/handlers/content_handler_relationship.inc and modify the $max_delta as follow.
/** * Add a delta selector for multiple fields. */ function options_form(&$form, &$form_state) { $field = $this->content_field; parent::options_form($form, $form_state); // Only add the form gadget if the field is multiple. if ($field['multiple']) { $max_delta = $field['multiple']; // 1 means unlimited. if ($max_delta == 1) { /* Modify the default value of $max_delta from 10 to whatever u like */ //$max_delta = 10; $max_delta = 20; } $options = array('-1' => t('All')); for ($i = 0; $i < $max_delta; $i++) { $options[$i] = $i + 1; } $form['delta'] = array( '#type' => 'select', '#options' => $options, '#default_value' => $this->options['delta'], '#title' => t('Delta'), '#description' => t('The delta allows you to select which item in a multiple value field to key the relationship off of. Select "1" to use the first item, "2" for the second item, and so on. If you select "All", each item in the field will create a new row, which may appear to cause duplicates.'), ); } }
Done =)
Update @ 2011-09-23: Please use this with extremely caution since it is not a good approach to hack the Drupal module. Thanks eosrei
The Drupal project strongly recommends never editing any core or contrib code. You can and should do this with hook_form_alter() in a custom module. http://api.drupal.org/api/drupal/developer–hooks–core.php/function/hook_form_alter/6
LikeLike
O, i never thought about using the hook_form_alter(). Thanks for your reminder. =P
LikeLike
It’ll be slightly more code, but you can copy/paste much of it from cck/includes/views/handlers/content_handler_relationship.inc. More importantly, you’ll be able able to upgrade CCK when a new release comes out without breaking your site.
LikeLike
ya~ let me update the post later when i have time.
LikeLike