Changing Taxa vocabulary to a entity for eml export

Adding a taxa vocabulary to DEIMS dataset EML export.

Inigo in added a taxa entity to capture taxa information.  However I had already created a hierarchical taxonomy vocabulary for storing taxa information. For example Betula nana term would be under Betula.  In the dataset content type I added a term reference field for the taxa vocabulary. When clicking on a taxa term one gets a list of the datasets associated with that term. 

But the EML display would need to be tweaked to use the taxa term reference field.  After a lot of searching I found that a vocabulary could be added to a content as an entity reference field.  (As a side note in Drupal 8 this is the way vocabularies are added.)  With the taxa vocabulary as an entity reference field I could modify the eml template files and add the taxa field to the EML Display.  Following are the steps I followed.

Cleaning up the taxa vocabulary and adding the taxa Level and Scientific Name to the vocabulary.

I added “Level” and “Scientific Name” custom fields to the taxa vocabulary. See screen capture below.  I didn’t add the other fields that Inigo did.  Just my preference to keep it simple. And I added the Scientific Name field because I could not figure out how to reference term name in the eml template. 

My taxa came from datasets where the taxa information was not checked.  Therefore a fair amount of cleanup was needed in addition to populating the taxa “Level” and “Scientific Name” fields.  I used a view data export to export my taxa terms as a comma delimited file and used Excel to check for misspelling, duplicates and other errors. Once done I edited the taxonomy on Drupal to make any corrections or merges.  Since I didn’t want to edit each term to add the Level and Scientific name I added theses values to fields in the Excel file, saving the file as a csv file and using a feed import to update the terms.

Unfortunately I had already added the taxa vocabulary to the dataset content as a term reference field. Instead of deleting it and recreating the taxa vocabulary as a entity reference I found a module- EntityReference migration ( to change the term reference field in my dataset to an entity reference field.

Modifications to the custom eml module templates.

Add a template file, eml--taxonomy-term--taxa.tpl.php, for the level field and scientific name fields (profiles/deims/modules/custom/eml/templates) with the following:

  <taxonRankName><?php print render($content['field_level']); ?></taxonRankName>
  <taxonRankValue><?php print render($content['field_scientific_name']); ?></taxonRankValue>

Modify/add to the eml--node--data-set.tpl.php the following at line 74:

       <?php print "<taxonomicCoverage>"; ?>
      <?php print render($content['field_dataset_taxa']); ?>
       <?php print "</taxonomicCoverage>"; ?>

Note: In the datasets content, the taxa vocabulary entity reference field machine name is call field_dataset_taxa.  Also note that in Inigo added "<taxonomicCoverage>" to the eml--taxa--taxa.tpl.php file but I found it gave invalid eml when I had multiple terms.  Putting it here just prints the tag once followed by as many taxa as there are associated with a dataset.

Modifications to dataset Manage Display EML tab.

Despite the warning "The ordering of these elements is hard-coded in the template files of the EML module. Re-ordering here will not change any output in EML." you can enable and rearrange some fields.  Here you will need to enable Taxa as an "EML element" and move it up below Date Range.  See print screen below.

I now get eml with species from my DEIMS site!

Print screens