如何在drupal中查询cck字段? [英] How to query cck field in drupal?

查看:179
本文介绍了如何在drupal中查询cck字段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

不幸的是,当我得到这个代码dsm返回和空值。

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);

我在krumo得到以下结果:

I get the following outcome in krumo:

... (Array, 1 element)
     0 (Array, 2 elements)
          email(string, 9 characters) aa@aa.com
          safe (string, 9 characters) aa@aa.com

有关如何加载内容的任何建议的cck电子邮件地址字段(aa@aa.com)转换成新字段?

Any suggestion on how to load the content of the cck email address field (aa@aa.com) into a new field?

非常感谢!

推荐答案

我可能会误会这里的东西,但是Krumo似乎告诉你, $ item_node-> field_job_email [0] 有一个'view'属性。

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

你尝试过 $ item_email = $ item_node-> field_job_email [0] ['safe']; / code>?

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

这篇关于如何在drupal中查询cck字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆