0

I am writing a module in which a fieldset containing a bunch of buttons gets added to the edit/add node form using hook_form_alter.

The fieldset(the buttons) are supposed to be connected to a certain widget for a field. For example maybe the body field widget of content type 'myContentType'. I always want the fieldset and the widget of the field to be placed together in the form, preferably with the fieldset above the widget. So to achieve this I thought I would use the #weight property of the form elements.

So in hook_form_alter I set:

$form['buttonFieldset'][#weight] = $form['body']['#weight'] - 1; 

Afterwards I check in the $form array and the weight of the button field did get set to a weight one smaller than the associated widget. I thought this would place it right above the textarea of the body, but this did not happen. Does anyone know why not? Or some other way to achieve what I want?

4

1 回答 1

0

尝试将您的 fielsdset 权重设置为 body 字段的权重,并将 body 字段在列表中移动到较低的位置。所以:

$form['buttonFieldset']['#weight'] = $form['body']['#weight'];
...
$form['body']['#weight'] = $form['body']['#weight'] + 1;

这很有效,特别是如果您将标题直接放在正文字段上方,因为 Drupal 似乎不喜欢移动标题字段,尽管更改了#weight它。我无法title向上移动以便在两者之间放置一些东西,titlebody我可以body向下移动。

于 2012-07-26T20:52:04.117 回答