I try to use wrappers to set node data.

it's ok with the title but it s no working with the summary or the body.

EntityMetadataWrapperException: Entity property summary doesn't support writing. in EntityStructureWrapper->setProperty() (line 450 of /home/*****/www/drupal7/sites/all/modules/community/entity/includes/entity.wrapper.inc).

it seams that it lacks $info['setter callback'].

is it a bug or is it not (yet) implemented ?

Comments

quazardous’s picture

I ve started to understand...

it's because I deal with the body EntityStructureWrapper ...

In my module I parse/wrap all the fields of an entity and I recrusivly iterate until I met an EntityValueWrapper.

I try to use set($value) against this value wrapper... for body structure it seams not to work...

I ll try a different way...

quazardous’s picture

Ok,

maybe I ve found a solution :

line 240 of entity.wrapper.inc add the default 'setter callback' :

class EntityStructureWrapper extends EntityMetadataWrapper implements IteratorAggregate {

  protected $propertyInfo = array(), $propertyInfoAltered = FALSE;
  protected $langcode = NULL;

  protected $propertyInfoDefaults = array(
    'type' => 'text',
    'getter callback' => 'entity_property_verbatim_get',
    'setter callback' => 'entity_property_verbatim_set', //NEW
    'clear' => array(),
  );
...

it seams to work for body structure at least

fago’s picture

Status: Active » Fixed

changing the defaults would affect any other property too. Anyway, adding the setter only for the summary is a no-go as it depends on the configured text-format, what might have security implications. You can set the whole formatted_text structure at once, though.

quazardous’s picture

if we think in a generic way, not allowing writing of a single value is not very "simple".

Imagine a module that just want to deal with basic type (string, integer). In example a module describing datasource to import and to map against fields of entities through entity wrapper...

This module just want to map an input record field X to an entity field Y (ie the summary part of the the body).
The module does not want to know the complexity of the underlaying structures that s what entity wrapper are for !!!
If property of a structure cannot be set alone ... the module have to make switch/case for all structure or at least query information throught field info api...

security aspect could be handled for each field of the structure or triggered after all fields are set.

fago’s picture

Title: Entity property summary doesn't support writing » Add write support for summary/value of formatted text
Category: support » task
Status: Fixed » Active

Yep, I agree this is unfortunate. I just had another look at it, and of course we can support it as long as we implement appropriate access checks.

As we cannot rely on the actual configured filter for the access check, we'll have to demand 'administer filters'. So we can add a verbatim setter to the properties in entity_property_text_formatted_info() + that 'setter permission'. Also, we need to cover that in the test cases then.

quazardous’s picture

ps : allowing setting all but not setting a part is weird

fago’s picture

Title: Add write support for summary/value of formatted text » Entity property summary doesn't support writing
Category: task » support
Status: Active » Fixed

If I don't have 'administer filters' I can't set a part if I don't have permission for the configured filter. Still I can set a new value with the default filter format (I may use) via setting all.

quazardous’s picture

sorry our messages crossed ...

thx for considering ;p

quazardous’s picture

I m not sure to understand all the security aspects...

but it seams to me that the propertyInfo is not alterable by hook_entity_property_alter() for EntityStructureWrapper ;p

cheers

fago’s picture

Category: support » task
Status: Fixed » Active

1. Just edit the function entity_property_text_formatted_info() and add the setter callbacks + the administer filter 'setter permission' (see API docs').
2. We need the tests to cover making use of the new functionality.

gorillaz.f’s picture

I meet this problem when i tried to change a comment body using rules (for a logging purpose but not want to use revision)
It works fine after setter_callback added, will it be committed ?

quazardous’s picture

hi,

I ve planned to work on it next week.

I not sure about the 'setter permission' part... so any help is welcome !

quazardous’s picture

I ve put a patch in http://drupal.org/node/1084042 for this issue

fago’s picture

Status: Active » Closed (duplicate)