I have a text field with text processing set to filtered text. I'm attempting to save a value to it using

$entity_metadata_wrapper->field_specs->set($value);

...where $value is a simple text string, "foo". It fails with this error: Invalid data value given. Be sure it matches the required data type and format. If I change the field to plain text format, it works fine.

getPropertyInfo() lists the field (see below), leading me to believe that it would be supported. Is it not, or do I need to process the value differently before saving?

[field_specs] => Array
        (
            [label] => Specs
            [type] => text_formatted
            [description] => Field "field_specs".
            [getter callback] => entity_metadata_field_verbatim_get
            [setter callback] => entity_metadata_field_verbatim_set
            [access callback] => entity_metadata_field_access_callback
            [translatable] => 
            [field] => 1
            [required] => 
            [property info] => Array
                (
                    [value] => Array
                        (
                            [type] => text
                            [label] => Text
                            [sanitized] => 1
                            [getter callback] => entity_metadata_field_text_get
                            [setter callback] => entity_property_verbatim_set
                            [setter permission] => administer nodes
                            [raw getter callback] => entity_property_verbatim_get
                        )

                    [format] => Array
                        (
                            [type] => token
                            [label] => Text format
                            [options list] => entity_metadata_field_text_formats
                            [getter callback] => entity_property_verbatim_get
                            [setter callback] => entity_property_verbatim_set
                            [setter permissions] => administer filters
                        )

                )

            [auto creation] => entity_property_create_array
     )

Comments

rubymuse created an issue. See original summary.

mchaplin’s picture

Seeing this too.

cyb_tachyon’s picture

The issue is in `includes/entity.property.inc\entity_property_verify_data_type` - there is a switch function that hardcodes all of the data types, which does not include 'text_formatted'.

A simple fix is to add 'text_formatted' as a scalar, but it does not fix the long-term issue with other modules adding additional data types to validate.

Another fix would be to put the `default` as TRUE along with the 'unknown' case - I'm not sure why 'struct' is the default data type format.

See: https://www.drupal.org/node/1396046

That issue recommends using the correct sub-values, instead of the data shortcut.

$wrapper = entity_metadata_wrapper('node', $node, array('bundle' => $node->type));
$wrapper->field_profile_aboutus = array('value' => 'text');

Or

$wrapper = entity_metadata_wrapper('node', $node, array('bundle' => $node->type));
$wrapper->field_profile_aboutus->value = 'text';
cyb_tachyon’s picture

Status: Active » Needs review

rubymuse please confirm. I recommend marking 'Closed (works as designed)'.

Chris Matthews’s picture

Version: 7.x-1.6 » 7.x-1.x-dev
Status: Needs review » Closed (works as designed)