It is necessary to change the contents of the drupal 7 material field, how can this be done programmatically? How to use hook_field_storage_write ? Tell me who knows?
|
1 answer
To change the contents of the material field, you can use the following code:
$node = node_load($nid); $l = field_language('node', $node, 'field_number'); $node->field_number[$l][0]['value'] = 10; node_save($node); If the Entity API module is installed, you can use the Entity metadata wrappers :
$node = node_load($nid); $wrapper = entity_metadata_wrapper('node', $node); $wrapper->field_number->set(10); $wrapper->save(); The hook hook_field_storage_write () is called before writing the field values of an entity when it is created / modified, but is extremely inconvenient for changing the values of stored fields. For this purpose it is better to use hook_node_presave () (for nodes) or hook_entity_presave () (for all entities).
|