Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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
Comment #2
mchaplin CreditAttribution: mchaplin commentedSeeing this too.
Comment #3
cyb_tachyon CreditAttribution: cyb_tachyon as a volunteer and at Red Hat commentedThe 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.
Or
Comment #4
cyb_tachyon CreditAttribution: cyb_tachyon as a volunteer and at Red Hat commentedrubymuse please confirm. I recommend marking 'Closed (works as designed)'.
Comment #5
Chris Matthews CreditAttribution: Chris Matthews as a volunteer commented