[development] Help with form in drupal, 7

Fernando Correa da Conceição fernando at jaguaribe.net
Thu Dec 30 15:38:56 UTC 2010


I am updating a draggable form from drupal 6 to 7. If i change the value 
of weight on the select box, it changes and saves it, but if i drag and 
drop, it do not change the value. I found some samples, but they are 
only for drupal 6, where it works, i have made some changes from drupal 
6 and it is as this, the full file is at 
http://drupalcode.org/viewvc/drupal/contributions/modules/customfilter/customfilter.module?view=markup&pathrev=DRUPAL-7--1 

This is the only thing left to a drupal 7 version, and any help/tip is 
welcome, thanks.

function theme_customfilter_rules_form($vars) {
   $form = $vars['form'];

   $rows = array();
   if (isset($form['rules'])) {
     foreach (element_children($form['rules']) as $rid) {
       $row = array();

       $element = &$form['rules'][$rid];

       $element['prid']['#attributes']['class'] = 'rule-prid';
       $element['rid']['#attributes']['class'] = 'rule-rid';
       $element['weight']['#attributes']['class'] = 'rule-weight';

       $row[] = (
         // @todo Fix this for indentation
         //theme('indentation', $element['level']['#value']) .
         $element['name']['#value']
       );

       $row[] = (
         drupal_render($element['rid']) .
         drupal_render($element['prid']) .
         drupal_render($element['weight'])
       );
       $row[] = drupal_render($element['enabled']);
       $row[] = $element['operations']['add']['#value'];
       $row[] = $element['operations']['edit']['#value'];
       $row[] = $element['operations']['delete']['#value'];

       $rows[] = array(
         'data' => $row,
         'class' => array('draggable'),
       );
     }
   }

   if (!count($rows)) {
     $rows[] = array(
       array(
         'data' => t('There are no replacement rules currently defined.'),
         'colspan' => '6',
       )
     );
   }

   $header[] = t('Name');
   $header[] = t('Weight');
   $header[] = t('Enabled');
   $header[] = array(
     'data' => t('Operations'),
     'colspan' => '3',
   );

   drupal_add_tabledrag('customfilter-rules-tree', 'order', 'sibling', 
'rule-weight', NULL, NULL, TRUE);
   drupal_add_tabledrag('customfilter-rules-tree', 'match', 'parent', 
'rule-prid', 'rule-prid', 'rule-rid', TRUE);

   $args['header'] = $header;
   $args['rows'] = $rows;
   $args['attributes'] = array('id' => 'customfilter-rules-tree');
   return theme_table($args) .// theme($form);
     drupal_render_children($form);
}


More information about the development mailing list