My main focus is the ECK module, but I'm sure this could be useful to other developers as well. Unlike, user, node, taxonomy, profile2 profiles, etc, no properties or fields for any entity type I define using ECK. I know this is an ECK issue, but I would like to supply a patch to add in this functionality and could use your guidance in doing so.

Profile2 is a good example because it provides a select box for the "bundle type." That is exactly what would be useful in the ECK module. Can you give me any pointers as to what is required in order to make the type selection and potentially required or common properties available to rules for use in the "create entity" action? I've been reading through rules/modules/* code and profile2, but it isn't fully apparent to me. Any guidance would be much appreciated.

I will make sure to update documentation if I get this all sorted out.

Thank you in advance.

Comments

acrazyanimal’s picture

Title: How make rules aware of a custom entity's required properties/fields for use in "create entity" » How to make rules aware of a custom entity's required properties/fields for use in "create entity"
fago’s picture

Just provide good entity-property information, Rules makes heavily use of it. See http://drupal.org/node/1021466

Is ECK based upon the entity api module? If so, you can build upon the provided metadatacontroller which generates some basic metadata out of your entity's schema. Also, the views controller will pick up the infos you are providing there.

acrazyanimal’s picture

Yes it does rely on the entity api. I am not the maintainer of ECK, but would like to help them out with getting better rules integration. Plus, it is critical for a project I am currently working on. Thanks for the feedback.

Here is the property info hook code, but I cannot tell if there is anything out of place here.

function eck_entity_property_info(){
  module_load_include('inc', 'entity', 'entity.info');
  //dpm("In ECK entity property info");
  $info = array();
  // Add meta-data about the basic node properties.
  //$properties = &$info['entity_type']['properties'];
  foreach(EntityType::loadAll() as $entity_type){
    
    //@todo we should connect the label to the label set up for the 
    //property
    $stuff = entity_metadata_convert_schema("eck_{$entity_type->name}");
    foreach($stuff as $key => $property){
      $property['setter callback'] = "entity_property_verbatim_set";
      $property['getter callback'] = 'entity_property_verbatim_get';
      $property['description'] = $property['label'];
      //A couple of alter hooks so a module can alter the property info
      //of a given property, or even a specific property on a
      //specific entity_type
      drupal_alter("entity_property_{$key}_info", $property);
      drupal_alter("entity_property_{$entity_type->name}_{$key}_info", $property);
      
      $stuff[$key] = $property;
    }
    $info[$entity_type->name]['properties'] = $stuff;
  }
  
  return $info;  
}
acrazyanimal’s picture

Hmm did some digging and I think that at least for the "type" property it would need also the following parameters in the info array:

'options list' => 'function_to_return_the_types',
'required' => TRUE,

Probably need the 'required' parameter for all others I want to appear there as well.

Thanks for making me take a second look the property info fago. I'll try this out.

fago’s picture

oh, yes sry they have to be marked as 'required'. Also, currently "create an entity" does not add in bundle-related required properties. It should though and could qualify as bug-report.

acrazyanimal’s picture

Status: Active » Closed (fixed)

Thanks again for the help fago.