Skip to main content
improved grammar
Source Link
avpaderno
  • 97.9k
  • 15
  • 164
  • 284

Drupal 8 : On hook_entity_insert how to How do I update a field value in hook_entity_insert()?

I want to update an field on hook_entity_insertin hook_entity_insert(). I tried inserting usingThe following code doesn't work.

$entity->field_range->value = 'test';
$entity->save();

and it didn't work.

AlsoI also tried loading from node object like this and, but still it didn'tdoesn't work.

$node = \Drupal::entityManager()->getStorage('node')->load($entity->id());
$node->set('field_range', 'test');
$node->save();

After inserting the node only iI will get the text "test" dynamically and it wontwon't work in hook_entity_presave()hook_entity_presave().

Any help on how to update an field on hook_entity_insert will be nice. Thanks in advance.

Drupal 8 : On hook_entity_insert how to update a field value

I want to update an field on hook_entity_insert. I tried inserting using

$entity->field_range->value = 'test';
$entity->save();

and it didn't work.

Also tried loading from node object like this and still it didn't work.

$node = \Drupal::entityManager()->getStorage('node')->load($entity->id());
$node->set('field_range', 'test');
$node->save();

After inserting the node only i will get the text "test" dynamically and it wont work in hook_entity_presave().

Any help on how to update an field on hook_entity_insert will be nice. Thanks in advance.

How do I update a field value in hook_entity_insert()?

I want to update an field in hook_entity_insert(). The following code doesn't work.

$entity->field_range->value = 'test';
$entity->save();

I also tried loading from node object, but still it doesn't work.

$node = \Drupal::entityManager()->getStorage('node')->load($entity->id());
$node->set('field_range', 'test');
$node->save();

After inserting the node only I will get the text "test" dynamically and it won't work in hook_entity_presave().

Any help on how to update an field on hook_entity_insert will be nice. Thanks in advance.

added 115 characters in body
Source Link
Ram
  • 1.3k
  • 15
  • 37

I want to update an field on hook_entity_insert. I tried inserting using

$entity->field_range->value = 'test';
$entity->save();

and it didn't work.

Also tried loading from node object like this and still it didn't work.

$node = \Drupal::entityManager()->getStorage('node')->load($entity->id());
$node->set('field_range', 'test');
$node->save();

After inserting the node only i will get the text "test" dynamically and it wont work in hook_entity_presave().

Any help on how to update an field on hook_entity_insert will be nice. Thanks in advance.

I want to update an field on hook_entity_insert. I tried inserting using

$entity->field_range->value = 'test';
$entity->save();

and it didn't work.

Also tried loading from node object like this and still it didn't work.

$node = \Drupal::entityManager()->getStorage('node')->load($entity->id());
$node->set('field_range', 'test');
$node->save();

Any help on how to update an field on hook_entity_insert will be nice. Thanks in advance.

I want to update an field on hook_entity_insert. I tried inserting using

$entity->field_range->value = 'test';
$entity->save();

and it didn't work.

Also tried loading from node object like this and still it didn't work.

$node = \Drupal::entityManager()->getStorage('node')->load($entity->id());
$node->set('field_range', 'test');
$node->save();

After inserting the node only i will get the text "test" dynamically and it wont work in hook_entity_presave().

Any help on how to update an field on hook_entity_insert will be nice. Thanks in advance.

Source Link
Ram
  • 1.3k
  • 15
  • 37

Drupal 8 : On hook_entity_insert how to update a field value

I want to update an field on hook_entity_insert. I tried inserting using

$entity->field_range->value = 'test';
$entity->save();

and it didn't work.

Also tried loading from node object like this and still it didn't work.

$node = \Drupal::entityManager()->getStorage('node')->load($entity->id());
$node->set('field_range', 'test');
$node->save();

Any help on how to update an field on hook_entity_insert will be nice. Thanks in advance.