Problem

RDF Mappings aren't exported for SPARQL Views resource types, which is an entity using Entity API. Instead, rdf_mapping is NULL.

Example:

<?php
function test_feature_default_sparql_views_type() {
  $items = array();
  $items['kasabi_factbook_country'] = entity_import('sparql_views_resource_type', '{
    "name" : "kasabi_factbook_country",
    "label" : "Country (Kasabi Factbook)",
    "rdf_mapping" : []
  }');
  return $items;
}
?>

Comments

Anonymous’s picture

One potential problem I see is that 'node' is hardcoded in rdf_mappings_features_rebuild. I doubt whether this is the cause of the problem, but something to note.

<?php
rdf_mapping_save(array(
  'type' => 'node',
  'bundle' => $bundle,
  'mapping' => $mapping,
));
?>
scor’s picture

that is a known missing feature, see comment in rdf_mappings_features_export_options()

Anonymous’s picture

What would be the first step in making this a non-missing feature?

Anonymous’s picture

Title: Features export doesn't work for some entities » support all entities in feature export
Category: bug » task

I think I figured out the first step. Will post a patch when it's ready.

Anonymous’s picture

Status: Active » Needs review

This patch gets as far as exporting the mapping. It still needs some work to update rdf_mappings_features_revert() and rdf_mappings_features_rebuild()

Anonymous’s picture

StatusFileSize
new3.01 KB

Patch attached.

scor’s picture

Status: Needs review » Needs work
+++ b/rdfx.features.inc
@@ -26,8 +29,15 @@ function rdf_mappings_features_export($data, &$export, $module_name = '') {
+  foreach (entity_get_info() as $entity_type => $entity) {
+    foreach ($entity['bundles'] as $bundle_type => $bundle) {
+      $bundles[$bundle_type] = $bundle['label'];
+    }
+  }

This should clash is there are bundles with the same machine name in different entity types. we need to have a unique key here like entity-bundle. The label should also reflect that, e.g. "Node: Article".

Anonymous’s picture

Status: Needs work » Needs review
StatusFileSize
new2.63 KB

Thanks for mentioning that, good thinking. This works using the compound key.

Anonymous’s picture

StatusFileSize
new2.56 KB

Whoops, there was a line left in there that I meant to delete but just uncommented by accident.

scor’s picture

Status: Needs review » Needs work

Looking good.

minor nitpick:

+++ b/rdfx.features.inc
@@ -10,11 +10,12 @@ function rdf_mappings_features_export($data, &$export, $module_name = '') {
+    $export['features']['rdf_mappings'][$entity_type][$bundle_type] = $rdf_mapping;

I find bundle_type confusing... bundle_name would be more accurate and in line with core conventions.

Anonymous’s picture

Status: Needs work » Needs review
StatusFileSize
new2.56 KB

bundle_name it is, then :)

Anonymous’s picture

StatusFileSize
new2.95 KB

Forgot to load $rdf_mapping in the first function. This doesn't seem to be needed, so I'm not sure whether we should take it out and just load the mapping in the render function or not.

Also, this adds the fix to the last function.

scor’s picture

StatusFileSize
new2.92 KB

The syntax in the feature's .info file also needs to be updated to include the entity type.

Anonymous’s picture

I'm not sure what change you made there. Can you highlight the code in a comment?

scor’s picture

Status: Needs review » Needs work
+++ b/rdfx.features.inc
@@ -10,10 +10,13 @@ function rdf_mappings_features_export($data, &$export, $module_name = '') {
+    if ($rdf_mapping = rdf_mapping_load($entity_type, $bundle_name)) {
+      $export['features']['rdf_mappings'][$entity_type . '-' . $bundle_name] = $rdf_mapping;
     }
+++ b/rdfx.features.inc
@@ -40,15 +50,19 @@ function rdf_mappings_features_export_render($module, $data, $export = NULL) {
+    $parts = explode('-', $entity_type_bundle);
+    $entity_type = $parts[0];
+    $bundle_name = $parts[1];
scor’s picture

Status: Needs work » Needs review
Anonymous’s picture

The syntax in the feature's .info file also needs to be updated to include the entity type.

I'm confused as to what you mean here.

scor’s picture

please generate a feature with #12 and inspect the .info file. the feature elements are not right and do not contain the bundle name. The $export array in rdf_mappings_features_export() can only have three levels of nesting (any deeper element will be lost).

Anonymous’s picture

Status: Needs review » Reviewed & tested by the community

Ah, ok, I get what you were saying now.

Works like a charm for me.

scor’s picture

Status: Reviewed & tested by the community » Fixed

Glad it works Lin. Clay was also able to test it on IRC.

Fixed with http://drupalcode.org/project/rdfx.git/commit/8b2df89

Status: Fixed » Closed (fixed)

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

Anonymous’s picture

Issue summary: View changes

forgot <