0

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

1

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.

How to use EFQ

8
  • These values are already saved. How can I manipulate it on the fly?
    – vintorg
    Commented Nov 14, 2013 at 23:55
  • How about hook_field_prepare_view()?
    – vintorg
    Commented Nov 15, 2013 at 0:11
  • 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."
    – leexonline
    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.
    – vintorg
    Commented Nov 15, 2013 at 0:42
  • Sorry, I have edited my answer to reflect this.
    – leexonline
    Commented Nov 15, 2013 at 1:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.