I have a client who:

  • needs custom citation styles;
  • has slightly hijacked Biblio fields (some fields are used in ways they were not really intended for);
  • has a few custom Biblio publication types in addition to the standard types.

Furthermore, I have to map some data that does not belong to the Biblio schema.

For these reasons, I need a custom CSL style, custom type mapping, and custom field mapping.

I'm thinking about overriding theme_biblio_citeproc_style(), and then subclassing csl_mapper in order to define my own mappings. However, the citeproc class instanciates the csl_mapper class directly, so to build a custom mapper I'd also have to subclass citeproc, and override its init() method, duplicating most of that function. Would you look favorably to a patch where a mapper object would be passed as argument to citeproc's constructor, instead of having citeproc instanciating it? Do you have other/better ideas to facilitate custom mappings?

Thanks.

CommentFileSizeAuthor
#6 biblio-map-alter-1944498.patch2.09 KBdavid lesieur

Comments

rjerome’s picture

That would be one option, but I wonder if a new "alter" hook, called from biblio_get_map might be a better alternative, since it could be used universally for all other maps as well.

Below, I've illustrated a call to drupal_alter (in the "biblio_get_map" function), and a corresponding hook_biblio_map_alter function.

What do you think of this idea?

function biblio_get_map($type, $format) {
  $map = unserialize(db_result(db_query("SELECT %s FROM {biblio_type_maps} WHERE format='%s'", array($type, $format))));
  if ($type == 'export_map' && empty($map)) {
      $schema = drupal_get_schema('biblio');
      $fieldnames = array_keys($schema['fields']);
      asort($fieldnames);
      $map = array_fill_keys($fieldnames, 1);
  }

  drupal_alter('biblio_map', $map, $type, $format);
    
  return $map;
}

function biblio_biblio_map_alter(&$map, $type, $format) {
  if ($type == 'field_map' && $format== 'csl') {
    $map['title'] = 'my_title_field';
  }
}
david lesieur’s picture

This is an interesting idea. However, in my specific case, I also need to use more than one map, so using map 'csl' won't do.

If we could also pass the $format as an argument to citeproc's contructor, and then to csl_mapper's constructor, both classes would be free from hardcoded mentions of the 'csl' map. In combination with the new hook, I think we'd have solved my problem nicely.

In csl_mapper::map_field(), there are also some hardcoded (contributor-related) mappings that are merged into biblio_get_map()'s result. If we have the new hook, perhaps those mappings would belong to an implementation of that hook?

I guess not many people are facing the issues I'm facing here. So I'd be happy to code & test this strategy before anything gets committed in Biblio, to ensure that it fully resolves the issues.

rjerome’s picture

Hmm, without the details of your use case, it's hard for me to to make too many suggestions. I'm still not clear on why you need "multiple" maps, but I'll take your word for it. If you want to hack something up and run it by me, that's fine.

On a related note, this issue got me to thinking about using tokens for mapping, but that's not going to happen real soon.

david lesieur’s picture

Right, tokens would be great to map non-Biblio data! Pushing this further, we could even imagine taking fields from non-Biblio entity types and render that data through CiteProc!

I'm okay with the idea of hacking something and submitting a patch here for review. By then, perhaps I'll be able to better explain some use cases. Your guidance on how you'd see this additional flexibility incorporated into Biblio (with the idea of a new hook) was very helpful; I'll follow that direction and we'll see how it turns out. Thanks!

david lesieur’s picture

Assigned: Unassigned » david lesieur
david lesieur’s picture

Title: Custom CSL mapper » Hook for allowing modules to alter Biblio's maps
Status: Active » Needs review
StatusFileSize
new2.09 KB

I have managed to work around the need for multiple maps by having the client clean some of their data, and by manipulating the node data in an override of theme_biblio_citeproc_style() before it gets rendered by CiteProc.

However, I have made good use of the new hook you have suggested in #1. Here's a patch that provides that hook.

rjerome’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

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

Anonymous’s picture

Issue summary: View changes

Added details.