I have a field in a node where users entered data in an inconsistent format. I need to parse that data (it's HTML) and re-format it so it looks correct. Where is the best place to do this?
1 Answer
1) Use EntityFieldQuery to load a list of entity ID's.
2) Load the full entity using entity_load.
3) Optionally wrap the entity using entity_metadata_wrapper.
4) For each entity, manipulate the field to your desire then save the entity. If you have it in a wrapper use $entity_wrapper_object->save() or if using the entity it's entity_save.
If you want to do this quickly and easily, install the devel module and use the PHP execute page @ example.com/devel/php. Go through each step and ensure you have the correct data to work with at each stage.
Optionally you could use something like VBO to create a view and manipulate the data using a PHP field. This might be easier depending on your experience level.
-
These values are already saved. How can I manipulate it on the fly?– vintorgCommented Nov 14, 2013 at 23:55
-
-
The values are not already saved, that's why the function is called 'presave' and the description states: "This hook is invoked from node_save() before the node is saved to the database." Commented Nov 15, 2013 at 0:16
-
The values are saved, and exist in the entity (a commerce product entity). They have been butchered, and there are too many of them. So, I need to modify them pre-render to clean them up.– vintorgCommented Nov 15, 2013 at 0:42
-