Drupal drupal_get_form

发布于 2024-09-11 13:22:06 字数 1618 浏览 8 评论 0原文

我试图在 div 中获取 twitter_admin_form 和 twitter_user_settings 表单。

/**
 * Get twitter form for user
 * @param $account
 * @type user object
 */
function getTwitterForm($account){
    //module_load_include('inc', 'twitter');
    module_load_all();
    $twitter_form =  drupal_get_form('twitter_admin_form');
    return $twitter_form;
}

我收到一个 drupal 错误。

警告:call_user_func_array() [function.call-user-func-array]:第一个参数预计是一个有效的回调,“twitter_admin_form”在第 372 行的 .../includes/form.inc 中给出。< /p>

。twitter.module

/**
 * Implementation of hook_meu()
 */
function twitter_menu() {
  $items = array();

  $items['admin/settings/twitter'] = array(
    'title' => 'Twitter setup',
    'description' => 'Twitter module settings',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('twitter_admin_form'),
    'access arguments' => array('administer site configuration'),
    'file' => 'twitter.pages.inc'
  );

  $items['user/%user_category/edit/twitter'] = array(
    'title' => 'Twitter accounts',
    'page callback' => 'twitter_user_settings',
    'page arguments' => array(1),
    'access arguments' => array('add twitter accounts'),
    'load arguments' => array('%map', '%index'),
    'weight' => 10,
    'file' => 'twitter.pages.inc',
    'type' => MENU_LOCAL_TASK,
  );

  return $items;
}

I不确定我做错了什么。 twitter_admin_form 没有任何参数,因此我认为获取和显示它会很简单。

我是新的表单/菜单,所以我不能 100% 确定 %user_category、%map 和 %index 是什么以及如何将它们传入。

您如何知道有效的表单是什么?

I trying to get the twitter_admin_form and twitter_user_settings form in a div.

/**
 * Get twitter form for user
 * @param $account
 * @type user object
 */
function getTwitterForm($account){
    //module_load_include('inc', 'twitter');
    module_load_all();
    $twitter_form =  drupal_get_form('twitter_admin_form');
    return $twitter_form;
}

I get a get a drupal error.

warning: call_user_func_array() [function.call-user-func-array]: First argument is expected to be a valid callback, 'twitter_admin_form' was given in .../includes/form.inc on line 372.

twitter.module

/**
 * Implementation of hook_meu()
 */
function twitter_menu() {
  $items = array();

  $items['admin/settings/twitter'] = array(
    'title' => 'Twitter setup',
    'description' => 'Twitter module settings',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('twitter_admin_form'),
    'access arguments' => array('administer site configuration'),
    'file' => 'twitter.pages.inc'
  );

  $items['user/%user_category/edit/twitter'] = array(
    'title' => 'Twitter accounts',
    'page callback' => 'twitter_user_settings',
    'page arguments' => array(1),
    'access arguments' => array('add twitter accounts'),
    'load arguments' => array('%map', '%index'),
    'weight' => 10,
    'file' => 'twitter.pages.inc',
    'type' => MENU_LOCAL_TASK,
  );

  return $items;
}

I'm not sure what I'm doing wrong. The twitter_admin_form doesn’t have any arguments hence I thought it would be simple to get and display.

I’m new forms/menu so I’m not 100% sure what %user_category, %map and %index are and how to pass them in.

How do you know what the valid forms are?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

情归归情 2024-09-18 13:22:06

当您调用drupal_get_form时,您提供一个表单ID,这是Drupal需要调用的函数。您遇到的问题是 Drupal 找不到该函数:twitter_admin_form

它要么位于包含文件中,而您需要包含它,要么您已将其命名为其他名称。

When you call drupal_get_form you supply a form id, which is the function that Drupal needs to call. The problem you are experiencing is that Drupal cannot find the function: twitter_admin_form.

Either it's located in an include file, and you need to include it, or you have named it something else.

凝望流年 2024-09-18 13:22:06

您收到的错误源于以下行:

$twitter_form = drupal_get_form('twitter_admin_form');

它期望“twitter_admin_form”是一个有效的回调函数,但找不到它。这可能是因为您调用时未包含相关文件“twitter.pages.inc”。

您可以通过以下方式修复该问题:(

module_load_include('inc', 'twitter', 'twitter.pages');

鉴于代码示例中的注释行,您似乎已经尝试过类似的操作,但忘记提供要包含的文件的名称)。

The error you get stems from the line:

$twitter_form = drupal_get_form('twitter_admin_form');

It expects 'twitter_admin_form' to be a valid callback function, but can't find it. This is probably because the related file 'twitter.pages.inc' is not included at the time of your call.

You could fix that via a:

module_load_include('inc', 'twitter', 'twitter.pages');

(Given the commented line in your code sample, you seem to have tried something like this, but forgot to give the name of the file to include).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文