Changing the position of Flags in the node edit form

Changing the position of Flags in the node edit form

Posted 08/12/2009 - 14:10 by State68

Using the Flag module it is possible to add flags to your node edit forms. For example, you might want to give your users the option of flagging a node for review by a senior editor, or flagging a node as complete but in need of subediting.

At the moment there is no way of easily changing the position of these flags (they're all grouped together) within the node edit form: they default to a weight of 1, and that's that. However, it is pretty easy to change the weight of the flags via a simple custom module. In that module, invoke hook_form_alter as follows:

<?php
function flag_move_form_alter(&$form, $form_state, $form_id){
   
$flags = flag_get_flags('node', $form['type']['#value'], $user);
    if(
count($flags)){
       
$form['flag']['#weight'] = 999;
    }
?>

Just change 999 to whatever weight you want (-999 will almost always place the flags at the top of the node edit form; 999 will place them at the bottom).