0

Im using entity api. How to update record in entity api

i have:

class ExampleTaskController extends EntityAPIController {

  public function create(array $values = array()) {
    global $user;
    $values += array(
       'title' => '',
       'description' => '',
      'created' => REQUEST_TIME,
      'changed' => REQUEST_TIME,
      'uid' => $user->uid,
    );
     return parent::create($values);
  }

Then:

$task = entity_create('ExampleTask', array('description' => "alamakota");
entity_create($task);

if my task have id=1 how to perform update on record? I want change 'description' to 'newtext' in record with id =1

  • Welcome to Drupal Answers :) The duplicate refers specifically to nodes, but the principle is the same for any entity type so you can use any of the methods outlined in the accepted answer – Clive Jun 9 '14 at 10:47
  • I have seen it before but this is not an answer working in drupal7. Now i have solution it is: – mbahojlo Jun 9 '14 at 11:53
  • I;m not sure what you mean, the other answers are for Drupal 7 only (they won't work with Drupal 6). I use those methods 20 times a day, they're definitely correct. – Clive Jun 9 '14 at 11:54
  • I have seen it before but this is not an answer working in drupal7. Now i have solution it is: $node = reset(entity_load('ExampleTask', array(2))); $node->'description' ='newtext' ; $node->save(); The diffrence is that you have to use array [array(1)] === [id =1], not an id direct In answer You provided Id is direct. And one thing more im not in hook_method, im in form submit... – mbahojlo Jun 9 '14 at 12:00
  • Again, not sure what you mean I'm afraid, the code in your previous comment can't possibly work because the object returned from entity_load() is a stdClass and doesn't have a save() method. If you're using save(), you simply must be using the EntityMetadataWrapper method, as in the accepted answer to the other question. Unless your entity controller has something custom on it, but that still doesn't invalidate the other answers, which are definitely accurate. – Clive Jun 9 '14 at 12:02

Browse other questions tagged or ask your own question.