Closed (duplicate)
Project:
Entity API
Version:
7.x-1.x-dev
Component:
Entity property wrapper
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
20 Jan 2011 at 10:12 UTC
Updated:
15 Mar 2011 at 10:52 UTC
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
Comment #1
quazardous commentedI 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...
Comment #2
quazardous commentedOk,
maybe I ve found a solution :
line 240 of entity.wrapper.inc add the default 'setter callback' :
it seams to work for body structure at least
Comment #3
fagochanging 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.
Comment #4
quazardous commentedif 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.
Comment #5
fagoYep, 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.
Comment #6
quazardous commentedps : allowing setting all but not setting a part is weird
Comment #7
fagoIf 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.
Comment #8
quazardous commentedsorry our messages crossed ...
thx for considering ;p
Comment #9
quazardous commentedI 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
Comment #10
fago1. 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.
Comment #11
gorillaz.f commentedI 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 ?
Comment #12
quazardous commentedhi,
I ve planned to work on it next week.
I not sure about the 'setter permission' part... so any help is welcome !
Comment #13
quazardous commentedI ve put a patch in http://drupal.org/node/1084042 for this issue
Comment #14
fagoso let's stay with #1084042: Entity property summary doesn't support writing