What would it take to add support for new entity types to UUID Features?

As I understand it, only nodes, files, vocabularies and terms are currently supported. Is the design goal behind UUID Features strictly limited to those types? Or is there an idea that entity instances in general are worth supporting?

Specifically: To be able to capture Bean (fieldable-block entity) instances in Features would be solid gold.

Categorized as "Support Request" rather than "Feature Request" in case there's actually some way to achieve this currently.

CommentFileSizeAuthor
#13 uuid_entity_features.tar_.gz4 KBgnucifer

Comments

kelvinwong’s picture

+1

mpgeek’s picture

There's a patch available for Bean-instance export here: #1849668: Add support for Bean exporting (deployable bean instances).

Jeffrey C.’s picture

Status: Active » Closed (duplicate)

As far as I know, no, currently there's no way to achieve this. Anyone who has a different idea is welcome to reopen this issue. Marking this duplicate of #1849668: Add support for Bean exporting (deployable bean instances)..

saltednut’s picture

Title: All entity types? » Refactoring needed to support all entities that have UUIDs
Category: support » feature
Status: Closed (duplicate) » Active
Issue tags: +demo_framework

Even though @beanluc is talking about supporting beans, that is just one example. This is not a duplicate thread about adding the bean support.

@Jeffrey C. Tucking this issue away as a duplicate task changes nothing: this is what people want from the module.

In an ideal scenario, this module would be programmed in such a way that any new entity type that is introduced to the UUID ecosystem could easily be supported. This is by no means a simple task, but it is what I would expect most users would assume the module to do when first installing it.

Right now, it seems that every entity supported is handled through its own includes. This may be the only way to do it, but I'm bumping this as a Feature request anyway, hopefully at least to get a dialogue going about this problem.

Perhaps we can figure something out from an API/plugin standpoint?

saltednut’s picture

Component: Miscellaneous » Code
mpgeek’s picture

Maybe a uuid_features API does make sense. Modules that provide entities know how to create/modify/save instances... could we not implement a generic entity exporter, then leave the logical details of export/import/rebuild up to the client modules themselves? Would that mean uuid_features defines an api for integration? Just throwing out ideas...

Jeffrey C.’s picture

Yes, that makes sense to me. Currently I don't have time to work on that, would be happy to commit if there's a working patch.

mpgeek’s picture

I'm short on time for general entity export as well, but I will be working on the Bean instance exporter #1849668: Add support for Bean exporting (deployable bean instances).. Perhaps looking at all of the entity types side-by-side will produce some sort of general factorization. Right now it feels like a radical shift in architecture/responsibility between features_uuid and the providing modules.

In any case, I would like to hear ideas on how this could be implemented. Is there some supporting functionality in teh Entity API that could help?

saltednut’s picture

@mpgeek The main problem here is that there is no shared schema for entity properties. Nodes use nid, have a title field, etc. Taxonomy terms require a tid and vid. Beans have a bid. This makes it difficult to support entities on a general level.

However, there are things that can be done in in regard to field handling, so that we can employ some re-use and reduce code bloat/inconsistencies.

One example of this is the patch in #1904946: Nodes should be able to export file fields where I take the code for file handling out of the taxonomy_term include and turn it into a more generalized solution that all entity types can employ for file field serialization. (That patch needs review, btw!) We shouldn't need to handle file field exports on an individual entity level. The file fields are always the same. You could use this patch and add to the bean patch so that beans support image/file fields. They're going to need to do that anyway...

In general, using the entity api in shared code situations rather than entity specific functions or methods is a good direction. It would not be ideal to have every entity supported handling file fields differently.

Another idea, just to create some consistency in the codebase, would be using a generic handler for imports: entity_save - this could be used instead of node_save, taxonomy_term_save etc. Doesn't actually reduce any code - but its good practice to use the API wherever possible.

saltednut’s picture

Issue tags: -demo_framework

removing tag

gumanoed’s picture

Issue summary: View changes

Any luck to add support of my personal entity type to UUID_features (and get fields and data from my entity tipe bundles to the feature code)?

I need some information how i can realise support of my entity type.
I'm edditing the code in sites/all/modules/uuid_features
I added to the uuid_features.module

function uuid_features_entity_info_alter(&$entity_info) {
  // Provide a list of entities that provide bundles
  // to be exported by uuid_features.
  $entity_types = array('bean', 'node', 'taxonomy_term', 'fruit'); 

A copied includes/uuid_bean.features.inc to includes/uuid_fruit.features.inc and make changes (what i found) in code. Changes bean to fruit.

And a dind't find in includes/modules/bean.inc so i copied includes/modules/node.inc to includes/modules/fruit.inc and made changes of variables node to fruit.

So, i get structure, but i can't get bundles and fields to my feature code.

sites/all/modules/medicusessential$ grep -rh "fruit"
    'fruit_apple' => array(
      'machine_name' => 'fruit_apple',
      'entity_type' => 'fruit',
    'fruit_banana' => array(
      'machine_name' => 'fruit_banana',
      'entity_type' => 'fruit',
    'fruit_fruit' => array(
      'machine_name' => 'fruit_fruit',
      'entity_type' => 'fruit',
      'name' => 'fruit',
      'label' => 'fruit',
    'fruit' => array(
      'name' => 'fruit',
      'label' => 'fruit',
features[eck_bundle][] = fruit_apple
features[eck_bundle][] = fruit_banana
features[eck_bundle][] = fruit_fruit
features[eck_entity_type][] = fruit
features[field_instance][] = fruit-apple-field_apple_body
features[field_instance][] = fruit-fruit-field_body
  // Exported field_instance: 'fruit-apple-field_apple_body'
  $field_instances['fruit-apple-field_apple_body'] = array(
    'entity_type' => 'fruit',
  // Exported field_instance: 'fruit-fruit-field_body'
  $field_instances['fruit-fruit-field_body'] = array(
    'bundle' => 'fruit',
    'entity_type' => 'fruit',

Can someone help me with information how to make it works?

gumanoed’s picture

We succeeded realize support of our own entity tipe in Features_UUID to export (and import) data from our own entities.
In uuid_features.module
* add name of your entity tipe (our is fruits)
$entity_types = array('bean', 'node', 'taxonomy_term', 'fruits');

* in function function uuid_features_file_field_export(&$export, $entity_type) { ... add your antity description
switch ($entity_type) {
case "taxonomy_term":
$export_bundle = $export->vocabulary_machine_name;
break;
case "bean":
$export_bundle = $export->type;
break;
case "node":
$export_bundle = $export->type;
break;
case "fruits":
$export_bundle = $export->type;
break;
}

* In function uuid_features_features_api() { add
$components['uuid_fruits'] = array(
'name' => t('Content_fruits'),
'feature_source' => TRUE,
'default_hook' => 'uuid_features_default_content',
'default_file' => FEATURES_DEFAULTS_INCLUDED,
'file' => drupal_get_path('module', 'uuid_features') . '/includes/uuid_fruits.features.inc',
);

* create the file includes/uuid_fruits.features.inc from includes/uuid_node.features.inc and replace all "node" to your entity name (our is "fruits".

* But check lines 45, 80 161 function $node = node_load($nid, NULL, TRUE); will not work with entity. You need use entity_load() function with anothor input variables list
$fruits = entity_load('fruits', $ids = array($nid));
$fruits = $fruits[$nid];
(actualy this function works with $id variable, but not to change too much in code we uname $nid name for this variables, but actualy it is ID)

We have an issue with filefields load from our entity. But it's temporary problem. I think we will solve it.

I think i will make post about it. If you have questions - write me on gumanoed at gmail dot com.

gnucifer’s picture

StatusFileSize
new4 KB

I have begun to implement generic support for entities as a separate module. It is in a pretty early stage, and I'm posting it here as it is in case it will be useful for anyone. It will need more polishing, and will perhaps be released as a separate project (or contribute to uuid_features if it is possible to merge in the functionality in a clean way).

gnucifer’s picture

Might as well put it on github: https://github.com/gnucifer/uuid_entity_features

Use the github-version instead, the version in the previous post is broken.