Follow up on #1228872: RDF default mappings override empty values. We could fix the core bug in rdfx by implementing our own fork of rdf_mapping_save() -> rdfx_mapping_save(), which would be smarter about not forcing a default mapping in the case of an empty mapping.

Comments

dropbydrop’s picture

I hope this to get fixed soon, if it's related to http://drupal.org/node/1271498 (I cannot delete mappings and vocabularies)

dropbydrop’s picture

Please give a hint how to empty/reset the rdf_mapping table. thanks
just delete the records, or the site will break?

dropbydrop’s picture

+1

mlncn’s picture

Posted a patch to fix core, works like this:

  $default_mapping = _rdf_get_default_mapping($mapping['type']);
  $only_in_default = array_diff($default_mapping, $mapping['mapping']);
  $mapping['mapping'] += $only_in_default;
David Lesieur’s picture

This is what I do in rdf_mapping_save():

  $mapping['mapping'] += _rdf_get_default_mapping($mapping['type']);
  $mapping['mapping'] = array_filter($mapping['mapping']);

So any value in $mapping['mapping'] that evaluates to FALSE now means that no mapping is desired for the corresponding key. Use of operator += prevents those from being overridden by the default mappings, and in the end the FALSE values get filtered out.

David Lesieur’s picture

Actually, my "fix" only works on the first save. The second time the mappings happen to get loaded and saved, the defaults find their way back into the mappings. Perhaps we could have a new special attribute type 'none' to explicitly mean "no mapping". I have not tested this idea, but it looks like the core RDF module will simply reject mappings whose attribute type is neither 'property', 'rel', or 'rev'.

David Lesieur’s picture

Issue summary: View changes
StatusFileSize
new498 bytes

Okay, so to get rid of default mappings, I'm now defining overrides like this:

<?php
  $rdf_mappings['node']['my_node_type'] = array(
    'name' => array(
      'predicates' => array(),
      'type' => '',
    ),
  );
?>

Except for a PHP notice in rdf.module's function rdf_rdfa_attributes() (which can be fixed with the attached patch), things seem to work smoothly.
A fork of rdf_mapping_save() is avoided with this approach.