If you have a form_alter that add's to the $form['options'] array (for nodes), and wish to implement a pseudo-field of that with hook_field_extra_field then for some reason the placement into the form fails.


/**
 * Implements hook_form_alter().
 */
function test_field_form_alter(&$form, $form_state, $form_id) {
  switch ($form_id) {
    case 'article_node_form':
      $form['options']['myfield'] = array(
        '#type' => 'select',
        '#title' => t('test form item'),
        '#options' => array(0 => t('None'))
      );
      
    break;
  }
}

/**
 * Implements hook_field_extra_fields()
 *
 * Field hook to allow sorting of the domain settings field.
 */
function test_field_field_extra_fields() {
  $return = array();
  foreach (node_type_get_names() as $name => $value) {
    $return['node'][$name]['form']['options'] = array(
        'label' => t('test options'),
        'description' => t('test textfield'),
        'weight' => 30,
    );
  }

  return $return;
}

Seems hook_field_extra_field might be being overwritten by other field layout decisions when there is an existing $form structure.

As you can see in the screenshot, the form item has been moved, but in the form it's still always stuck in $form['options'],

ideas? did i set the form array wrong in the hook, or is this a bug? I've tried many combinations

Comments

rooby’s picture

If you hadn't noticed, the other 'options' on the node form are also not able to be moved around on the manage fields form.

Two questions that mean the same thing:
If you want to put a new element in the 'options' then why do you not want it displayed with the options.
If it isn't to go with the options then why put it in the 'options' array?

I'm going to go out on a limb and say what you want to do is not going to be supported here.
However, you might be very interested in the Renderable elements module, which does allow you to move the 'options' elements wherever you like (it's pretty awesome). If you have time to watch it there is a screencast linked from the project page that shows how it works (note you don't need display suite).

dgtlmoon’s picture

Ahh, I see, yes that makes sense

Pproblem is maybe then with the REL module, because it flattens out $form['options']['status'] to just $form['status']

and there's a lot of contrib modules that look for $form['options']['status']

Incidentally I found this bug whilst moving the 'premium' field in the "premium content" module which is located as $form['options']['premium'] but then that field wasnt working anymore so.. hmm not sure what todo here! might be that those modules need to put that field somewhere better?

rooby’s picture

Sorry, originally I misread your code snippets in the original post and I now see the problem you describe.

I would say your problem in this case is:
In your test_field_field_extra_fields() function:

    $return['node'][$name]['form']['options'] = array(

Should be:

    $return['node'][$name]['options'] = array(

Yeah, I have run into problems in regards to that issue with rel too.

I think it would be great if the core options were all their own fields that could be dragged around in the manage fields form and that other modules that alter or use them in some way use a better method of locating them, but that is not going to happen in the short term.