Offshot of http://drupal.org/node/832046#new:

- EntityStructureWrapper::getPropertyInfo() replaces _ with -: "$name = str_replace('_', '-', $name);". Why is it doing that? Because I have a property named "thread_id", and if I define it like that, it throws an exception and if I define it as "thread-id", then it works fine but obviously isn't going to find the related data. Do I need to define a getter callback?

Comments

fago’s picture

Hm, that should work just with 'thread_id'. Internally the property will be re-named to thread-id, but the default getter should work with that. What was the exception you got?

I don't think this internal rename thing was a good idea, perhaps we should just go and change the API and remove it.

Berdir’s picture

This is the exception:

Error message
EntityMetadataWrapperException: Unknown data property thread-id. in EntityStructureWrapper->getPropertyInfo() (line 292 of sites/all/modules/entity/entity_metadata/entity_metadata.wrapper.inc).

This is the configuration of thread_id that doesn't work:

    'thread_id' => array(
      'type'  => 'integer',
      'label' => t('Private message thread ID'),
      'description' => t('Private message thread ID'),
    ),

This works:

    'thread-id' => array(
      'type'  => 'integer',
      'label' => t('Private message thread ID'),
      'description' => t('Private message thread ID'),
      'getter callback' => 'privatemsg_thread_get_id',
    ),

/**
 * Returns the thread ID of the passed in message.
 *
 * Function is requried because properties with _ can not be directly defined.
 */
function privatemsg_thread_get_id($privatemsg_message) {
  return $privatemsg_message->thread_id;
}
Berdir’s picture

Ok, I got it. I have to specifiy 'entity_metadata_verbatim_get' as the getter callback and then it works :)

I guess that should be documented somewhere and then this issue can be closed...

fago’s picture

Status: Active » Fixed

ok, I changed it to always use underscores -> API change!

I think that makes it much clearer to use, but any modules exposing the property names to end users (like Rules) have to replace the underscore by dashes themselves in order to get prettier names.

Berdir’s picture

Status: Fixed » Active

Uhm. Something is not working correctly here.

I think this totally broke integration for privatemsg.module, because our entity is called "privatemsg_message". That is now displayed as "privatemsg-message" but doesn't seem to be translated back to "privatemsg_message" so it fails to access it (and any property below it).

It always fails with the following (or similiar) rules debug message "13.991 ms Unable to get variable privatemsg-message:author, it is not defined." and we're positive that this worked at some point :)

BenK’s picture

Since I'm working with Berdir on Private Message Rules integration, tracking this thread...

fago’s picture

Status: Active » Fixed

ouch, thanks. let's handle that in #919112: variable names with underscores are broken

BenK’s picture

I can confirm that the "privatemsg-message:author" issue is now fixed after fago's commit on the #919112 thread referenced in #7. :-)

We're still having an issue with "privatemsg_message:thread-id", but I need to check with Berdir if that one is still using the old dash format. We're currently getting the following error message:

10.518 ms Unable to apply data selector privatemsg_message:thread-id: Unknown data property thread_id.

--Ben

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.