Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
system_element_info() defines a weight form element that uses #delta for its range in the select box:
$types['weight'] = array(
'#input' => TRUE,
'#delta' => 10,
'#default_value' => 0,
'#process' => array('form_process_weight', 'ajax_process_form'),
);
But then field_multiple_value_form() comes along and reuses that for the ordering of multiple field elements:
$element = array(
'#entity_type' => $instance['entity_type'],
'#entity' => $form['#entity'],
'#bundle' => $instance['bundle'],
'#field_name' => $field_name,
'#language' => $langcode,
'#field_parents' => $parents,
'#columns' => array_keys($field['columns']),
// For multiple fields, title and description are handled by the wrapping table.
'#title' => $multiple ? '' : $title,
'#description' => $multiple ? '' : $description,
// Only the first widget should be required.
'#required' => $delta == 0 && $instance['required'],
'#delta' => $delta,
'#weight' => $delta,
);
This means that for instance you can't use a weight form element as a widget for a FieldAPI field, because the values clash.
The fix I would suggest is to change the '#delta' for weight form elements to '#range' which seems more descriptive to me. It's probably a smaller change in FormAPI rather than FieldAPI too.
Comment | File | Size | Author |
---|---|---|---|
#2 | 1619286.drupal.delta-fight-fieldapi-formapi.patch | 9.58 KB | joachim |
Comments
Comment #1
tim.plunkettSeems reasonable. Not major though.
Comment #2
joachim CreditAttribution: joachim commentedWell there's no status for 'total PITA which from what I can tell so far makes a weight field type impossible or at least a mess to implement' ;)
Working on a patch now, and this comment in Field module rather takes the biscuit I feel:
Here's the patch. Let's see if I missed anything :)
Comment #15
larowlanI think this is outdated now for two reasons:
* field api now nests the widget under 'widget' so there should no longer be a collision with the actual widget structure
* https://www.drupal.org/project/weight (although using a select element) solves the original motivation of the issue
Going to mark it as outdated, please re-open if still required and provide some extra detail.
thanks