如何在drupal中查询cck字段?

发布于 2024-10-05 14:34:47 字数 1997 浏览 2 评论 0原文

我有两种内容类型(job_post 和 application),使用节点引用 + 节点引用 url 节点链接。当我单击 job_post 节点中的链接时,会创建一个新的申请节点,以便候选人可以填写其工作申请。我的目标是自动将 cck 电子邮件字段的内容从引用的 job_post 节点复制到应用程序节点中的 cck 电子邮件字段。

为了实现这一点,我创建了以下模块:

// Implementation of hook_perm()
      function mymodule_perm() {
 return array('copy cck field');
    }

 // Implementation of hook_node_api    

function mymodule_nodeapi(&$node, $op, $a3 = NULL, $a4  = NULL){
 switch ($op) {

//if the node is inserted in the database

      case 'prepare':
        //if node is a job application
   if($node->type == 'application') {

//get nid from referenced node (using url information    
    $item_nid = arg(3);

//load and build node content
    $item_node = node_load($item_nid);
    $item_node = node_build_content($item_node);

//retrieve data from cck email field in referenced job post node    
                            $item_email = $item_node->field_job_email[0]['view'];

//display result in  website to check if value is correctly loaded
                            dsm($item_email);

不幸的是,当我得到此代码时,dsm 返回并为空值。

当我对代码进行以下更改时:

//retrieve data from cck email field in referenced job post node    
                            $item_email = $item_node->field_job_email;

//display result in  website to check if value is correctly loaded
                            dsm($item_email);

我在 krumo 中得到以下结果:

... (Array, 1 element)
     0 (Array, 2 elements)
          email(string, 9 characters) [email protected]
          safe (string, 9 characters) [email protected]

有关如何加载 cck 电子邮件地址字段内容的任何建议 ([电子邮件受保护]) 到新字段?

太感谢了!

I have two content types (job_post and application) linked using the node reference + node reference url nodes. When I click a link in a job_post node, a new application node is created, so that candidates can fill out their job application. My goal is to automatically copy the content of an cck email field from the referenced job_post node to a cck email field in the application node.

To achieve this,I have created the following module:

// Implementation of hook_perm()
      function mymodule_perm() {
 return array('copy cck field');
    }

 // Implementation of hook_node_api    

function mymodule_nodeapi(&$node, $op, $a3 = NULL, $a4  = NULL){
 switch ($op) {

//if the node is inserted in the database

      case 'prepare':
        //if node is a job application
   if($node->type == 'application') {

//get nid from referenced node (using url information    
    $item_nid = arg(3);

//load and build node content
    $item_node = node_load($item_nid);
    $item_node = node_build_content($item_node);

//retrieve data from cck email field in referenced job post node    
                            $item_email = $item_node->field_job_email[0]['view'];

//display result in  website to check if value is correctly loaded
                            dsm($item_email);

Unfortunately when I get this code dsm returns and empty value.

When I make the following changes to the code:

//retrieve data from cck email field in referenced job post node    
                            $item_email = $item_node->field_job_email;

//display result in  website to check if value is correctly loaded
                            dsm($item_email);

I get the following outcome in krumo:

... (Array, 1 element)
     0 (Array, 2 elements)
          email(string, 9 characters) [email protected]
          safe (string, 9 characters) [email protected]

Any suggestion on how to load the content of the cck email address field ([email protected]) into a new field?

Thank you so much!

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

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

发布评论

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

评论(1

时光瘦了 2024-10-12 14:34:47

我可能会误解这里的一些内容,但 Krumo 似乎告诉您 $item_node->field_job_email[0] 没有“view”属性。

您是否尝试过 $item_email = $item_node->field_job_email[0]['safe'];

I might misunderstand something here, but Krumo seems to tell you that $item_node->field_job_email[0] does not have a 'view' property.

Have you tried $item_email = $item_node->field_job_email[0]['safe']; ?

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