What's wrong in my code for setting up entity title in a Computed Field? I have written inside a Computed Field's Computed Code section the following code:

&lt;?php
//work if the node is new and there is no value for the field yet
if (empty($entity_field[0]['value'])) {

  do {
    //calculate a promotion code
    $new_promotion_code = strtoupper(substr(md5(rand(999, time())), 0, 5));

    //check db for conflicts
    $query = new EntityFieldQuery();
    $query-&gt;entityCondition('entity_type', 'node')
      -&gt;entityCondition('bundle','gift')
      -&gt;fieldCondition('field_gift_code', 'value', $new_promotion_code)
      -&gt;addMetaData('account', user_load(1));
    $result = $query-&gt;count()-&gt;execute();
  } while($result &gt; 0);

  //assign the field value
  $entity_field[0]['value'] = $new_promotion_code;

  //option#1
  //$entity-&gt;title[0]['value'] = $new_promotion_code;
  //option#2
  //$entity-&gt;title[LANGUAGE_NONE][0]['value'] = $new_promotion_code;

  //presave the node with attached fields (not sure if this is working)
  field_attach_presave($entity_type, $entity);
}
?&gt;


This code works except the commented out section which includes two options for setting up same node's title. I am also not sure if field_attach_presave() works but I have no means to debug it and it just doesn't fail like field_attach_update().

Using Auto Entity Label is also a solution but the token ([node:field-gift-code:rawvalue] or [node:field-gift-code]) for this field just prints Array.

Any suggestions?
You can't do it all in the first box.

Use the Computed Code box to create a value for the field in $entity_field[0]['value']. 

Then use the Display code box to do something with this value.