在 Drupal 中以编程方式插入多个节点时出现日期错误

发布于 2024-09-25 19:35:03 字数 3113 浏览 3 评论 0原文

我正在构建一个 Drupal 模块,该模块(除其他外)在创建“team_match”类型的节点时创建多个“individual_match”类型的节点。 team_match 是相关个人比赛的集合。

我使用了 Advomatic,我在旧的 Stack Overflow 帖子中找到的。它工作得很好(意味着它创建了节点),但它返回了很多错误消息,所有错误消息都与空日期有关。

以下是 hook_nodeapi 函数的相关代码:

    case 'insert':
      // insert individual matches when a team match is created
      if($node->type == 'team_match') {
        // Create node of type 'individual_match'
        // will be a loop, once date errors are sorted out
        $form_state = array();
        $tmp_node = new stdClass(); 
        $tmp_node->type = 'individual_match';
        // create form for new node
        $form_state['values']['type'] = $tmp_node->type;
        $form_state['values']['status'] = 1;
        $form_state['values']['title'] = $node->title;
        $form_state['values']['uid'] = $node->uid;
        $form_state['values']['name'] = $node->name;
        $form_state['values']['op'] = t('Save');  // This seems to be a required value.
        // Create the content.
        drupal_execute($tmp_node->type.'_node_form', $form_state,  &$tmp_node);
      }
    break;

以下是错误消息:

  • warning: date_offset_get()期望参数 1 为 DateTime,在 /var/www/vhosts/example.com/httpdocs/sites/all/modules 中给出/date/date/date_elements.inc 第 491 行。
  • 警告:date_format() 期望参数 1 为 DateTime,在 /var/www/vhosts/example.com/httpdocs/sites/all/modules/date/date/ 中给出 null date_elements.inc 第 494 行。
  • 警告:date_format() 期望参数 1 为 DateTime,在 /var/www/vhosts/example.com/httpdocs/sites/all/modules/date/date/date_elements.inc 在线中给出 null 495.
  • 警告:date_offset_get() 期望参数 1 为 DateTime,在第 497 行的 /var/www/vhosts/example.com/httpdocs/sites/all/modules/date/date/date_elements.inc 中给出 null。
  • 警告:date_timezone_set () 期望参数 1 为 DateTime,在 /var/www/vhosts/example.com/httpdocs/sites/all/modules/date/date/date_elements.inc 第 498 行给出的 null。
  • 警告:date_timezone_set() 期望参数 1为 DateTime, null 在 /var/www/vhosts/example.com/httpdocs/sites/all/modules/date/date/date_elements.inc 第 499 行给出。
  • 警告:date_format() 期望参数 1 为 DateTime, null在 /var/www/vhosts/example.com/httpdocs/sites/all/modules/date/date/date_elements.inc 第 500 行给出。
  • 警告:date_format() 期望参数 1 为 DateTime,在 /var/ 中给出 null www/vhosts/example.com/httpdocs/sites/all/modules/date/date/date_elements.inc 第 501 行。
  • 警告:date_timezone_set() 期望参数 1 为 DateTime,在 /var/www/vhosts/example 中给出 null .com/httpdocs/sites/all/modules/date/date/date_elements.inc 第 509 行。
  • 警告:date_timezone_set() 期望参数 1 为 DateTime,在 /var/www/vhosts/example.com/httpdocs/ 中给出 null site/all/modules/date/date/date_elements.inc 第 510 行。
  • 警告:date_format() 期望参数 1 为 DateTime,在 /var/www/vhosts/example.com/httpdocs/sites/all/modules 中给出 null /date/date/date_elements.inc 第 511 行。
  • 警告:date_format() 期望参数 1 为 DateTime,在 /var/www/vhosts/example.com/httpdocs/sites/all/modules/date/date/ 中给出 null date_elements.inc 第 514 行。

I am building a Drupal module that (among other things) creates multiple nodes of type 'individual_match' when a node of type 'team_match' is created. A team_match is a collection of related individual matches.

I used the method explained on Advomatic, which I found in an old Stack Overflow post. It works great (meaning it creates the node) but it returns a lot of error messages, all pertaining to a null date.

Here is the relevant code from the hook_nodeapi function:

    case 'insert':
      // insert individual matches when a team match is created
      if($node->type == 'team_match') {
        // Create node of type 'individual_match'
        // will be a loop, once date errors are sorted out
        $form_state = array();
        $tmp_node = new stdClass(); 
        $tmp_node->type = 'individual_match';
        // create form for new node
        $form_state['values']['type'] = $tmp_node->type;
        $form_state['values']['status'] = 1;
        $form_state['values']['title'] = $node->title;
        $form_state['values']['uid'] = $node->uid;
        $form_state['values']['name'] = $node->name;
        $form_state['values']['op'] = t('Save');  // This seems to be a required value.
        // Create the content.
        drupal_execute($tmp_node->type.'_node_form', $form_state,  &$tmp_node);
      }
    break;

And here are the error messages:

  • warning: date_offset_get() expects parameter 1 to be DateTime, null given in /var/www/vhosts/example.com/httpdocs/sites/all/modules/date/date/date_elements.inc on line 491.
  • warning: date_format() expects parameter 1 to be DateTime, null given in /var/www/vhosts/example.com/httpdocs/sites/all/modules/date/date/date_elements.inc on line 494.
  • warning: date_format() expects parameter 1 to be DateTime, null given in /var/www/vhosts/example.com/httpdocs/sites/all/modules/date/date/date_elements.inc on line 495.
  • warning: date_offset_get() expects parameter 1 to be DateTime, null given in /var/www/vhosts/example.com/httpdocs/sites/all/modules/date/date/date_elements.inc on line 497.
  • warning: date_timezone_set() expects parameter 1 to be DateTime, null given in /var/www/vhosts/example.com/httpdocs/sites/all/modules/date/date/date_elements.inc on line 498.
  • warning: date_timezone_set() expects parameter 1 to be DateTime, null given in /var/www/vhosts/example.com/httpdocs/sites/all/modules/date/date/date_elements.inc on line 499.
  • warning: date_format() expects parameter 1 to be DateTime, null given in /var/www/vhosts/example.com/httpdocs/sites/all/modules/date/date/date_elements.inc on line 500.
  • warning: date_format() expects parameter 1 to be DateTime, null given in /var/www/vhosts/example.com/httpdocs/sites/all/modules/date/date/date_elements.inc on line 501.
  • warning: date_timezone_set() expects parameter 1 to be DateTime, null given in /var/www/vhosts/example.com/httpdocs/sites/all/modules/date/date/date_elements.inc on line 509.
  • warning: date_timezone_set() expects parameter 1 to be DateTime, null given in /var/www/vhosts/example.com/httpdocs/sites/all/modules/date/date/date_elements.inc on line 510.
  • warning: date_format() expects parameter 1 to be DateTime, null given in /var/www/vhosts/example.com/httpdocs/sites/all/modules/date/date/date_elements.inc on line 511.
  • warning: date_format() expects parameter 1 to be DateTime, null given in /var/www/vhosts/example.com/httpdocs/sites/all/modules/date/date/date_elements.inc on line 514.

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

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

发布评论

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

评论(1

嘴硬脾气大 2024-10-02 19:35:03

事实证明,这是“individual_match”内容类型上必需的 CCK 日期时间字段。在函数中设置它,或者不使其成为必需的,可以解决这个问题。

This proved to be a required CCK datetime field on the 'individual_match' content type. Setting it in the function, or not making it required, solves this problem.

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