Greetings!

Problem/Motivation

I've found a weird issue with the text formatted fields. Currently I'm working on a feeds.module based web-crawler, which saves the imported data through entity metadata wrappers to entities (currently only nodes). When it tries to save the attached text to a text formatted field, then it can not save it, because the validate() function on the text formatted field returns with FALSE, however, when I've tried to save this data to the field without calling the validate() function first, then it could be saved without any problem.
After some digging around I've found the validate issue root I think. It is in the entity_property_verify_data_type(), because when this text passed to this function as a string, then the $type is 'text_formatted' rather than "text". Because the type is "text_formatted", therefore this function uses the is_object($data) || is_array($data) validation on the data, which of course, returns with false.

Proposed resolution

As I can see the type is set in the constructor of the EntityMetadataWrapper(). First I've tried to hack this in the constructor, to set the proper "text" type for this field (which is available in the $info['property info']['value']['type'] path, if it is set), but then the set() function dropped an invalid data exception. So as a quick fix, I added this workaround to the entity_property_verify_data_type() function. I'm not sure what would be the proper fix of this issue right now, but I hope this bug report will be useful to start to develop a proper solution for this issue.

How to reproduce

This issue also could be tested on simplytest.me easily.

  1. Create a new instance with entity and devel modules.
  2. Check, if devel.module enabled. Only the first selected module is enabled by default on simplytest.me
  3. Create a new article with title only (empty node body).
  4. Navigate to the /devel/php page and insert the content of the test.txt and execute it.
  5. You'll probably see a message with "can not be saved".
  6. Check the content on the node/1, the body should be filled.
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mxr576 created an issue. See original summary.

mxr576’s picture

The mentioned quick fix for this issue.

mxr576’s picture

Issue summary: View changes
mxr576’s picture

Little simplification on the patch.

mxr576’s picture

Okay, probably this workaround does not work properly either, or at least, in my importer I found an issue with field value saving.
An other workaround is to set the Text processing on the field settings to plain text.