Drupal – Increase Views Relationship Delta Limit

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.'),
    );
  }
}

 

Now i got 20 delta options.

 

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

Advertisement

5 thoughts on “Drupal – Increase Views Relationship Delta Limit”

      1. 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.

        Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.