Is it possible to use this module in conjunction with editable views? Apparently EditableViews support editing entity metadata properties if a setter has been defined for the property. When using this feature of the EditableViews module in a Data Module view there properties drop down list is empty. I guess there's no setter callback defined?

If this is not currently possible I would appreciate some guidance of how to implement a custom solution allowing for in-line editing of Data Entity properties.

Comments

strainyy created an issue. See original summary.

joachim’s picture

Version: 7.x-1.0-alpha7 » 7.x-1.x-dev
Category: Support request » Feature request

It's probably just a case of defining a setter callback on the properties we declare for Data table fields.

In *most* cases, we can use 'entity_property_verbatim_set'.

strainyy’s picture

Status: Active » Needs review
StatusFileSize
new2.14 KB

I've figured it out and produced a patch.

Just note that with the current patch all your column names in your table must be lower case, otherwise the entity properties can't be found!

joachim’s picture

Status: Needs review » Needs work

Thanks for the patch. A few things I'm not sure about though:

  1. +++ b/data.views.inc
    @@ -22,9 +22,9 @@ function data_views_data() {
    +      'entity type' => 'data_' . $table->name,
    

    This belongs in Data Entity module, not here, as Data tables are only entity types if Data Entity sets them up.

  2. +++ b/data_entity/data_entity.info.inc
    @@ -20,6 +20,7 @@ function data_entity_entity_property_info() {
    +        'save callback' => 'entity_metadata_data_entity_save',
    

    Are you sure this is in the right hook? I've looked at Entity module, and I'm pretty sure this belongs in hook_entity_info().

    Also, are you sure we need this? Look at entity_save() -- we can get by without this if we specify a controller implementing EntityAPIControllerInterface, which our controller does.

  3. +++ b/data_entity/data_entity.module
    @@ -309,4 +320,3 @@ function data_entity_feed_unique_callback(FeedsSource $source, $entity_type, $bu
    -
    

    Please avoid changing whitespace in patches!

strainyy’s picture

StatusFileSize
new1.7 KB

joachim, thanks for reviewing!

Apologies for the patch cleanliness - I'm a relatively new contributor.

Please review the updated patch. Hopefully it addresses most of the issues you raised above.

For the second issue you raised around using entity_save instead of the custom callback, that doesn't seem to work as you need to pass "entity_type" as a parameter into entity_save. Whatever function you pass into the 'save callback' argument of hook_entity_info() only receives the particular entity being saved.

joachim’s picture

> For the second issue you raised around using entity_save instead of the custom callback, that doesn't seem to work as you need to pass "entity_type" as a parameter into entity_save. Whatever function you pass into the 'save callback' argument of hook_entity_info() only receives the particular entity being saved.

I don't really follow what you mean.

entity_save() is *always* a correct way to save an entity.

This is the code for entity_save():

function entity_save($entity_type, $entity) {
  $info = entity_get_info($entity_type);
  if (method_exists($entity, 'save')) {
    return $entity->save();
  }
  elseif (isset($info['save callback'])) {
    $info['save callback']($entity);
  }
  elseif (in_array('EntityAPIControllerInterface', class_implements($info['controller class']))) {
    return entity_get_controller($entity_type)->save($entity);
  }
  else {
    return FALSE;
  }
}

So that tries several things:

1. if the entity class has a save method, it calls that
2. if the entity info has a save callback, it calls that
3. if the entity controller class implements the EntityAPIControllerInterface interface, then it calls save() on the controller.

Option 3 is the same as the code you've put in your save callback. So with your code, option 2 happens, and then the controller save() is called. Without your save callback, the controller save() is called. Same thing, less code :)

strainyy’s picture

StatusFileSize
new669 bytes

Ah! I get you now. Indeed, I've tested it without defining a 'save callback' argument and it everything's fine and dandy.
Might have experienced the magic of drush cc and conflated that with adding the 'save callback' argument...

In any case, I've attached the small code change needed as a patch for your review.

Thanks again joachim :)

strainyy’s picture

Status: Needs work » Needs review
ar-jan’s picture

Thanks for the patch, it works nicely.

  • joachim committed 2164b84 on 7.x-1.x authored by strainyy
    Issue #2662936 by strainyy: Added support for Editable Views.
    
joachim’s picture

Status: Needs review » Fixed

@ar-jan: feel free to mark issues as RTBC when you review them.

Thanks everyone! Committed, and I'll make a new release soon.

Status: Fixed » Closed (fixed)

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