【问题标题】:Drupal hook_form_alter weight controlDrupal hook_form_alter 权重控制
【发布时间】:2013-03-18 01:19:45
【问题描述】:

尝试在新的内容类型添加表单中添加一些额外的表单项。

还可以尝试增加提交和预览的权重。

function mymodule_form_alter(&$form, &$form_state, $form_id){
  //add some $form items here

  $form['actions']['submit']['#weight'] = 2000;
  $form['actions']['preview']['#weight'] = 2001;
}

但不知何故,提交和预览按钮仍然位于那里添加的新项目上方。

【问题讨论】:

  • 尝试将您想要较高的项目的权重设置为较低的数字?另外,这个问题属于Drupal Answers

标签: php drupal drupal-7 drupal-fapi


【解决方案1】:

尝试将#weight 属性添加到$form['actions'] 包装器。

您当前的代码更改了 actions wrapper 内 2 个按钮的权重,并且不会影响包装器的权重。

例如见以下代码:

function mymodule_form_alter(&$form, &$form_state, $form_id)
{
    //add some $form items here

    $form['actions']['#weight'] = 2000;
}

希望这行得通。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多