For an application for Field Collection I'm implementing, the order of fields is irrelevant, and it would be nice to be able to switch off display of field weight in the field Settings [I'd be quite happy with no reordering ability in this case.]

I guess it's possible to hide the page elements ("Show row weights", the + and table column, etc) in CSS: is there a better way?

Comments

nhck’s picture

Title: Field Collection Setting: enable/disable Weight? » Field Collection Settings: Make weight optional.

There is no way to do this yet, but I think its a feature request worth noting.

semiaddict’s picture

I am not sure this is the best way to do it, but you could achieve this by overriding theme_field_multiple_value_form

Here's an example (change MY_THEME to the theme name and MY_FIELD_NAME to the name of the field) :


/**
 * Implements theme_field_multiple_value_form().
 */
function MY_THEME_field_multiple_value_form($variables) {
  
  $element = $variables['element'];
  $output = '';
  
  // allows the disabling of the table drag for specif fields
  $draggable = !in_array($element['#field_name'], array('MY_FIELD_NAME'));

  if ($element['#cardinality'] > 1 || $element['#cardinality'] == FIELD_CARDINALITY_UNLIMITED) {
    $table_id = drupal_html_id($element['#field_name'] . '_values');
    $order_class = $element['#field_name'] . '-delta-order';
    $required = !empty($element['#required']) ? theme('form_required_marker', $variables) : '';

    $header = array(
      array(
        'data' => '<label>' . t('!title !required', array('!title' => $element['#title'], '!required' => $required)) . "</label>",
        'colspan' => 2,
        'class' => array('field-label'),
      ),
    );
    if($draggable){
      $header[] = t('Order');
    }
    $rows = array();

    // Sort items according to '_weight' (needed when the form comes back after
    // preview or failed validation)
    $items = array();
    foreach (element_children($element) as $key) {
      if ($key === 'add_more') {
        $add_more_button = &$element[$key];
      }
      else {
        $items[] = &$element[$key];
      }
    }
    usort($items, '_field_sort_items_value_helper');

    // Add the items as table rows.
    foreach ($items as $key => $item) {
      $item['_weight']['#attributes']['class'] = array($order_class);
      if(!$draggable){
        $item['_weight']['#attributes']['style'][] = 'display:none;';
      }
      $delta_element = drupal_render($item['_weight']);
      if($draggable){
        $cells = array(
          array(
            'data' => '',
            'class' => array('field-multiple-drag'),
          ),
          drupal_render($item),
          array(
            'data' => $delta_element,
            'class' => array('delta-order'),
          ),
        );
        $rows[] = array(
          'data' => $cells,
          'class' => array('draggable'),
        );
      }
      else{
        $cells = array(
          drupal_render($item) . $delta_element,
        );
        $rows[] = array(
          'data' => $cells,
        );
      }
    }

    $output = '<div class="form-item">';
    $output .= theme('table', array('header' => $header, 'rows' => $rows, 'attributes' => array('id' => $table_id, 'class' => array('field-multiple-table'))));
    $output .= $element['#description'] ? '<div class="description">' . $element['#description'] . '</div>' : '';
    $output .= '<div class="clearfix">' . drupal_render($add_more_button) . '</div>';
    $output .= '</div>';

    if($draggable){
      drupal_add_tabledrag($table_id, 'order', 'sibling', $order_class);
    }
  }
  else {
    foreach (element_children($element) as $key) {
      $output .= drupal_render($element[$key]);
    }
  }

  return $output;

}
semiaddict’s picture

Issue summary: View changes

Clarification

jmuzz’s picture

Issue summary: View changes
Status: Active » Fixed

I'd try using a form_alter hook to change the _weight element. Possibly change it to hidden, or set its #access to false, or unset it altogether.

Hope this helps.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

firewaller’s picture

I know this is closed, but I just wanted to report that I couldn't get #2 or #3 working, but I ended up using this contrib module: No Table Drag.