I'm working on properly setting the property metadata for the new Entity Registrations module. Registrations are a custom entity and is associated with a generic entity type, E.g., node, user, term, product, etc. It has entity_id and entity_type schema fields. For Views and Rules integration, I want to return the actual Entity object in hook_entity_property_info(). I'm trying something like this,
$properties['entity'] = array(
'label' => t("Associated Entity"),
'description' => t("The entity this registration is associated with."),
'type' => 'entity',
'schema field' => 'entity_id',
);
The documentation states that when the type is entity,
The entity has to be represented using an EntityMetadataWrapper.
This is where I get lost, though. What doest that mean exactly and what are the steps to implement? Thanks!
Comments
Comment #1
levelos commentedChanging the title here to reflect the underlying problem I'm trying to solve. In Entity Registraiton, we have a custom registration entity that includes properties for host entity type and host entity id. Combined, these can easily give us the host entity, but I'm unclear how to expose that relationship in Rules and Views. Also wondering if it makes sense to load the host entity objet and set it as a property in entity class __construct() method, E.g.,
Any guidance is appreciated, this is a real blocker right now for getting a stable release of Entity Registrations. Thanks!
Comment #2
levelos commentedChanging title to reflect underlying question.
Comment #3
jpontani commentedIt means the property you're adding must be an EntityMetadataWrapper object. The following code sets the entity property to a new EntityMetadataWrapper based on the attached entity type and ID.
Comment #4
levelos commentedThanks for that great clarification @jpontani, that gets the host entity loaded correctly when I load the registration. Does that help with Views or Rules relationships? They weren't available with that change alone. Any tips there?
Comment #5
alexweber commentedRules/Views integration is automatically provided for all custom properties.
You just need to declare them, preferrably specifying a metadata controller class extending EntityDefaultMetadataController.