Tell me more ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

for my content type I have this computed field code and when I update existing node everything is ok, but when I create new node, menu_get_object return empty values and drupal display this error message "EntityMalformedException: Missing bundle property on entity of type node. in entity_extract_ids() (line 7562 of /var/www/dev/testpage/includes/common.inc)." and nothing was saved. When I used dpm() in devel it show me that after creating new content $node is empty, but when I update node created before everything is OK.

$node = menu_get_object();
$start_time = field_get_items('node', $node, 'field_start_time');
$start_time = $start_time[0]['value'];
$entity_field[0]['value'] = '$start_time';

thanks a lot for your reply

share|improve this question

1 Answer

up vote 0 down vote accepted

menu_get_object() provides access to objects loaded by the current router item. For example, on the page node/%node, the router loads the %node object, and calling menu_get_object() will return that.

From: http://api.drupal.org/api/drupal/includes!menu.inc/function/menu_get_object/7

It returns empty upon creation because you add the node from "node/add/[content-type]" page but update it from "node/[nid]" and it can use the nid to load the node.

If you need just to duplicate the value from the start_time field of the same node, use this:

$entity_field[0]['value'] = $entity->field_start_time[0]['value'];
share|improve this answer
perfect. Thanks a lot – scooti Sep 17 '12 at 12:55
You're welcome :) – Ivanhoe123 Sep 17 '12 at 12:56

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.