0

I'm trying to remove the sticky option from the option bar and adding it to the user form.

function vacancies_form_vacature_node_form_alter(&$form, &$form_state, $form_id) {
// remove sticky field from default (option) location
unset($form['options']['sticky']);

//create new sticky field
$form['sticky'] = array (
    '#type' => 'checkbox',
    '#title' => 'Top vacature',
    '#default_value' => $form['#node']->sticky,
    '#weight' => -1,
);

dsm($form);

}

Weight of other elements go from 1 to 14 so -1 should put this form element on top. But with the code above it shows up at the end of the form.

How do I put the sticky button in the middle of my form?

1

This code:

$form['sticky'] = array (
    '#type' => 'checkbox',
    '#title' => 'Top vacature',
    '#default_value' => $form['#node']->sticky,
    '#weight' => -100,
);

works for me just fine. I don't know what's happening in your node edit form, but for me title field had #weight equal to -5, so obviously this item with weight -1 wouldn't show up on top.

3
  • as posted in my question my other elements have weight of 1 to 14 so -1 would be on top. Also note that I'm just putting it on top because I want to include it in the form and using an 'extreme' value (-1) to move it around. – FLY Mar 6 '12 at 8:07
  • What I just thought of is that there might be another implementation of hook_form_alter that changes fields weights running after your own hook_form_alter. So when your hook_form_alter is executed the weights of the fields are from 1 to 7 but they might be changed later. I would suggest you to check if it is the case. You can control the order in which hooks are called by setting module weight in system table. – Alex Petrov Mar 6 '12 at 21:11
  • good idea, I'll set the weight to -100 then to see if that changes anything. – FLY Mar 7 '12 at 8:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.