自定义字段node_save Drupal 7

时间:2015-10-15 08:22:44

标签: php drupal-7

我查找代码并尝试了这一点,但它似乎并没有将field_units变量保存在数据库中。任何帮助都会有很大帮助。

global $count,$user;
     try
        {
            $node = new stbClass();
            $node -> type = 'Quote';
            $node -> title = 'Quote Detail';
            $node -> language = LANGUAGE_NONE;
            $node -> path = array('alias' => 'quote_detial_node_form/'. $form_state['values']['field_data_field_units']);
            node_object_prepare($node);
            $node->uid = $user->uid;
            $node->is_new = True;
            $node->comment = 0;
            $node->promote = 0;
            $node->field_units['und'][0]['value'] = 'Row_quantity';
            $node->created = time();
            $node->changed = $node->created;
            node_submit($node);
            node_save($node);

            throw new Exception('Error Processing Request');

        }

1 个答案:

答案 0 :(得分:0)

尝试使用entity_metadata_wrapper(首先安装模块实体)

global $user;

  $values = array(
    'type' => 'Quote',
    'uid' => $user->uid,
    'status' => 1,
    'comment' => 0,
    'promote' => 0,
  );
  $entity = entity_create('node', $values);

  $ewrapper = entity_metadata_wrapper('node', $entity);

  $ewrapper->title->set('Quote Detail');
  $ewrapper->field_units->get(0)->set('Row_quantity');

  $ewrapper->save();