Browse Source

Added field for the publications to display records they link to. Added button to check for new fields for a bundle. Fixed ajax loading so titles don't appear

Stephen Ficklin 8 years ago
parent
commit
f1deb07241

+ 87 - 5
tripal/api/tripal.entities.api.inc

@@ -247,6 +247,7 @@ function tripal_create_bundle($args, &$error = '') {
       $function($bundle, $storage_args);
     }
 
+
     // Clear the entity cache so that Drupal will read our
     // hook_entity_info() implementation.
     global $language;
@@ -257,6 +258,46 @@ function tripal_create_bundle($args, &$error = '') {
     // Get the bundle object.
     $bundle = tripal_load_bundle_entity(array('name' => $bundle_name));
 
+    // Allow modules to add fields to the new bundle.
+    $modules = module_implements('bundle_create_fields');
+    foreach ($modules as $module) {
+      $function = $module . '_bundle_create_fields';
+      $info = $function('TripalEntity', $bundle);
+      foreach ($info as $field_name => $details) {
+        $field_type = $details['type'];
+
+        // If the field already exists then skip it.
+        $field = field_info_field($details['field_name']);
+        if ($field) {
+          continue;
+        }
+
+        // Create the field.
+        $field = field_create_field($details);
+        if (!$field) {
+          tripal_set_message(t("Could not create new field: %field.",
+              array('%field' =>  $details['field_name'])), TRIPAL_ERROR);
+        }
+      }
+    }
+
+    // Allow modules to add instances to the new bundle.
+    $modules = module_implements('bundle_create_instances');
+    foreach ($modules as $module) {
+      $function = $module . '_bundle_create_instances';
+      $info = $function('TripalEntity', $bundle);
+      foreach ($info as $field_name => $details) {
+        // If the field is already attached to this bundle then skip it.
+        $field = field_info_field($details['field_name']);
+        if ($field and array_key_exists('bundles', $field) and
+            array_key_exists('TripalEntity', $field['bundles']) and
+            in_array($bundle->name, $field['bundles']['TripalEntity'])) {
+          continue;
+        }
+        // Create the field instance.
+        $instance = field_create_instance($details);
+      }
+    }
   }
   catch (Exception $e) {
     $transaction->rollback();
@@ -276,6 +317,9 @@ function tripal_create_bundle($args, &$error = '') {
  *   The name of the bundle to refresh (e.g. bio_data_4).
  */
 function tripal_refresh_bundle_fields($bundle_name) {
+
+  $num_created = 0;
+
   // Get the bundle object.
   $bundle = tripal_load_bundle_entity(array('name' => $bundle_name));
   if (!$bundle) {
@@ -283,13 +327,51 @@ function tripal_refresh_bundle_fields($bundle_name) {
         array('%bundle' => $bundle_name));
     return FALSE;
   }
-  $term = tripal_load_term_entity(array('term_id' => $bundle->term_id));
+  // Allow modules to add fields to the new bundle.
+  $modules = module_implements('bundle_create_fields');
+  foreach ($modules as $module) {
+    $function = $module . '_bundle_create_fields';
+    $info = $function('TripalEntity', $bundle);
+    foreach ($info as $field_name => $details) {
+      $field_type = $details['type'];
+
+      // If the field already exists then skip it.
+      $field = field_info_field($details['field_name']);
+      if ($field) {
+        continue;
+      }
 
-  // Allow modules now add fields to the bundle
-  module_invoke_all('add_bundle_fields', 'TripalEntity', $bundle, $term);
+      // Create the field.
+      $field = field_create_field($details);
+      if (!$field) {
+        tripal_set_message(t("Could not create new field: %field.",
+            array('%field' =>  $details['field_name'])), TRIPAL_ERROR);
+      }
+    }
+  }
 
-  // Allow modules to update existing fields
-  module_invoke_all('update_bundle_fields', 'TripalEntity', $bundle, $term);
+  // Allow modules to add instances to the new bundle.
+  $modules = module_implements('bundle_create_instances');
+  foreach ($modules as $module) {
+    $function = $module . '_bundle_create_instances';
+    $info = $function('TripalEntity', $bundle);
+    foreach ($info as $field_name => $details) {
+      // If the field is already attached to this bundle then skip it.
+      $field = field_info_field($details['field_name']);
+      if ($field and array_key_exists('bundles', $field) and
+          array_key_exists('TripalEntity', $field['bundles']) and
+          in_array($bundle->name, $field['bundles']['TripalEntity'])) {
+        continue;
+      }
+      // Create the field instance.
+      $instance = field_create_instance($details);
+      $num_created++;
+      drupal_set_message(t("Created field: %field", array('%field' => $info[$field_name]['label'])));
+    }
+  }
+  if ($num_created == 0) {
+    drupal_set_message(t("No new fields were added."));
+  }
 }
 
 /**

+ 4 - 17
tripal/includes/tripal.entity.inc

@@ -302,23 +302,6 @@ function tripal_entity_view($entity, $type, $view_mode, $langcode) {
           $entity->content[$child_name]['#prefix'] .= '<div id="tripal-entity-' . $entity->id . '--' . $child_name . '" class="tripal-entity-unattached">';
           $entity->content[$child_name]['#suffix'] .= '</div>';
         }
-
-        // Add tooltip to each item.
-//         $matches = array();
-//         if (array_key_exists('term_vocabulary', $instance['settings'])) {
-//           $vocabulary = $instance['settings']['term_vocabulary'];
-//           $accession = $instance['settings']['term_accession'];
-//           $term = tripal_get_term_details($vocabulary, $accession);
-//           if ($term) {
-//             $tooltip_img = url(drupal_get_path('module', 'tripal') . '/theme/images/info.gif');
-//             $tooltip_text = $term['definition'] ? $term['definition'] : $term['name'];
-//             $entity->content[$child_name]['#prefix'] .= '' .
-//               '<div class="tripal-tooltip">' .
-//                 '<img src="' . $tooltip_img . '">' .
-//                 '<div class="tripal-tooltiptext">' . $tooltip_text . '</div>' .
-//               '</div>';
-//           }
-//         }
       }
     }
   }
@@ -342,7 +325,11 @@ function tripal_ajax_attach_field($id) {
     reset($result);
     $entity = $result[$entity_id];
 
+    // Get the element render array for this field and turn off the label
+    // display. It's already on the page.
     $element = field_view_field('TripalEntity', $entity, $field_name);
+    $element['#label_display'] = 'hidden';
+
     $content = drupal_render($element);
     return drupal_json_output(array(
       'id' => $id,

+ 2 - 11
tripal/theme/js/tripal.js

@@ -4,7 +4,7 @@
   Drupal.behaviors.myModuleSecureLink = {
     attach: function (context, settings) {
 
-      $(".tripal-entity-unattached .field-items").replaceWith('Loading... <img src="' + tripal_path + '/theme/images/ajax-loader.gif">');
+      $(".tripal-entity-unattached .field-items").replaceWith('<div class="field-items">Loading... <img src="' + tripal_path + '/theme/images/ajax-loader.gif"></div>');
       $(".tripal-entity-unattached").each(function() {
         id = $(this).attr('id');
         $.ajax({
@@ -14,19 +14,10 @@
           success: function(data){
             var content = data['content'];
             var id = data['id'];
-            $("#" + id).replaceWith(content);
+            $("#" + id + ' .field-items').replaceWith(content);
           }
         });
       });
-      
-      $(".tripal-tooltip").each(function() {
-        var field = $(this).next('.field');
-        $(this).detach();
-
-        if (field) {
-          field.children('.field-label').append($(this));
-        }
-      });
     }
   }
 })(jQuery);

+ 16 - 0
tripal/tripal.module

@@ -272,6 +272,17 @@ function tripal_menu() {
     'type' => MENU_CALLBACK,
   );
 
+  // Adds a +Check for new fields link on the 'Tripal Content Types' page.
+  $items['admin/structure/bio_data/manage/%/fields/check'] = array(
+    'title' => 'Check for new fields',
+    'description' => t('Check if new fields should be added to this content type.'),
+    'page callback' => 'tripal_check_new_fields',
+    'page arguments' => array(4),
+    'access arguments' => array('administer tripal'),
+    'file' => 'api/tripal.entities.api.inc',
+    'file path' => drupal_get_path('module', 'tripal'),
+    'type' => MENU_LOCAL_ACTION,
+  );
   return $items;
 }
 
@@ -586,3 +597,8 @@ function tripal_form_alter(&$form, $form_state, $form_id) {
     tripal_field_instance_settings_form_alter($form, $form_state);
   }
 }
+
+function tripal_check_new_fields($bundle_name) {
+  tripal_refresh_bundle_fields($bundle_name);
+  drupal_goto("admin/structure/bio_data/manage/$bundle_name/fields");
+}

+ 151 - 0
tripal_chado/includes/TripalFields/sio__references/sio__references.inc

@@ -0,0 +1,151 @@
+<?php
+
+class sio__references extends ChadoField {
+
+
+  // --------------------------------------------------------------------------
+  //                     EDITABLE STATIC CONSTANTS
+  //
+  // The following constants SHOULD be set for each descendent class.  They are
+  // used by the static functions to provide information to Drupal about
+  // the field and it's default widget and formatter.
+  // --------------------------------------------------------------------------
+
+  // The default lable for this field.
+  public static $default_label = 'References';
+
+  // The default description for this field.
+  public static $description = 'Records references by this publication.';
+
+  // Provide a list of instance specific settings. These can be access within
+  // the instanceSettingsForm.  When the instanceSettingsForm is submitted
+  // then Drupal with automatically change these settings for the instnace.
+  // It is recommended to put settings at the instance level whenever possible.
+  // If you override this variable in a child class be sure to replicate the
+  // term_name, term_vocab, term_accession and term_fixed keys as these are
+  // required for all TripalFields.
+  public static $default_instance_settings  = array(
+    // The short name for the vocabulary (e.g. shcema, SO, GO, PATO, etc.).
+    'term_vocabulary' => 'SIO',
+    // The name of the term.
+    'term_name' => 'references',
+    // The unique ID (i.e. accession) of the term.
+    'term_accession' => '000631',
+    // Set to TRUE if the site admin is allowed to change the term
+    // type. This will create form elements when editing the field instance
+    // to allow the site admin to change the term settings above.
+    'term_fixed' => FALSE,
+    // The table in Chado that the instance maps to.
+    'chado_table' => 'pub',
+    // The primary key column of hte table in Dhado.
+    'chado_column' => 'pub_id',
+    // The base table.
+    'base_table' => 'pub',
+  );
+
+  // The default widget for this field.
+  public static $default_widget = 'sio__references_widget';
+
+  // The default formatter for this field.
+  public static $default_formatter = 'sio__references_formatter';
+
+  // A boolean specifying that users should not be allowed to create
+  // fields and instances of this field type through the UI. Such
+  // fields can only be created programmatically with field_create_field()
+  // and field_create_instance().
+  public static $no_ui = FALSE;
+
+  /**
+   *
+   * @see TripalField::load()
+   */
+  public function load($entity, $details = array()) {
+    $field_name = $this->field['field_name'];
+    $field_type = $this->field['type'];
+    $field_table = $this->instance['settings']['chado_table'];
+    $field_column = $this->instance['settings']['chado_column'];
+    $base_table = $this->instance['settings']['base_table'];
+
+    // Set some defaults for the empty record.
+    $chado_record = $entity->chado_record;
+    $entity->{$field_name}['und'][0] = array(
+      'value' => '',
+    );
+
+    // Iterate through all of the _pub tables and look for any that have
+    // linked to this record. If os then add them.
+    $chado_tables = chado_get_table_names(TRUE);
+    $delta = 0;
+    foreach ($chado_tables as $chado_table) {
+      $matches = array();
+      if (preg_match('/^(.+?)_pub$/', $chado_table, $matches)) {
+        $reference_table = $matches[1];
+        // Find the base table this links to and get the fk columns that map it.
+        $schema = chado_get_schema($chado_table);
+        $fkeys = $schema['foreign keys'];
+        foreach ($fkeys as $linked_table => $fk_details) {
+          if ($linked_table == $reference_table) {
+            $fkleft = array_keys($fk_details['columns'])[0];
+            $fkright = $fk_details['columns'][$fkleft];
+          }
+        }
+        // Iterate through all of the records in the linker table that
+        // match the given pub ID.
+        $records = chado_generate_var($chado_table, array('pub_id' => $chado_record->pub_id), array('return_array' => TRUE));
+        foreach ($records as $record) {
+          // We want to add a 'type' and 'name' element to the values (at a
+          // minimum) for each of the records.  Unfortunately, every base table
+          // is different and their may not be an easy to identify name,
+          // so... we'll do the best we can.
+          $entity->{$field_name}['und'][$delta]['value'] = array();
+
+          // First get the type of record.
+          if (property_exists($record->$fkleft, 'type_id') and $record->$fkleft->type_id) {
+            $entity->{$field_name}['und'][$delta]['value']['rdfs:type'] = $record->$fkleft->type_id->name;
+          }
+          else {
+            // If there's not a type_id column then see if the table is mapped
+            // to a type.
+            $mapping = db_select('chado_cvterm_mapping', 'CVM')
+              ->fields('CVM')
+              ->condition('chado_table', $reference_table)
+              ->execute()
+              ->fetchObject();
+            if ($mapping) {
+              $cvterm = tripal_get_cvterm(array('cvterm_id' => $mapping->cvterm_id));
+              $entity->{$field_name}['und'][$delta]['value']['rdfs:type'] = $cvterm->name;
+            }
+          }
+
+          // Add in the name and uniquename (identifier) if those fields exist.
+          if (property_exists($record->$fkleft, 'name')) {
+            $entity->{$field_name}['und'][$delta]['value']['schema:name'] = $record->$fkleft->name;
+          }
+          if (property_exists($record->$fkleft, 'uniquename')) {
+            $entity->{$field_name}['und'][$delta]['value']['data:0842'] = $record->$fkleft->name;
+          }
+
+          // If this records is also a published entity then include that.
+          if (property_exists($record->$fkleft, 'entity_id')) {
+            $entity->{$field_name}['und'][$delta]['value']['entity'] = 'TripalEntity:' . $record->$fkleft->entity_id;
+          }
+
+          // If this is the organism table then we will create the name
+          // specially.
+          if (property_exists($record->$fkleft, 'genus')) {
+            $name = '<i>' . $record->$fkleft->genus . ' ' . $record->$fkleft->species . '</i>';
+            if (property_exists($record->$fkleft, 'infraspecific_name')) {
+              if ($record->$fkleft->type_id) {
+                $name .= ' ' . $record->$fkleft->type_id->name;
+              }
+              $name .= ' ' . $record->$fkleft->infraspecific_name;
+            }
+            $entity->{$field_name}['und'][$delta]['value']['schema:name'] = $name;
+          }
+          $delta++;
+        }
+      }
+    }
+  }
+
+}

+ 80 - 0
tripal_chado/includes/TripalFields/sio__references/sio__references_formatter.inc

@@ -0,0 +1,80 @@
+<?php
+
+class sio__references_formatter extends ChadoFieldFormatter {
+  // The default lable for this field.
+  public static $default_label = 'References';
+
+  // The list of field types for which this formatter is appropriate.
+  public static $field_types = array('sio__references');
+
+
+  /**
+   *
+   * @see TripalFieldFormatter::settingsForm()
+   */
+  public function settingsForm($view_mode, $form, &$form_state) {
+
+  }
+
+  /**
+   *
+   * @see TripalFieldFormatter::view()
+   */
+  public function view(&$element, $entity_type, $entity, $langcode, $items, $display) {
+    $field_name = $this->field['field_name'];
+    $chado_table = $this->instance['settings']['chado_table'];
+
+    // First, organize the values by their types.
+    $ordered_items = array();
+    foreach ($items as $delta => $item) {
+      $type = array_key_exists('rdfs:type', $item['value']) ? $item['value']['rdfs:type'] : '';
+      $entity = array_key_exists('entity', $item['value']) ? $item['value']['entity'] : '';
+      $name = array_key_exists('schema:name', $item['value']) ? $item['value']['schema:name'] : '';
+      $identifier = array_key_exists('data:0842', $item['value']) ? $item['value']['data:0842'] : '';
+      if ($entity) {
+        list($entity_type, $entity_id) = explode(':', $entity);
+        $name = l(strip_tags($name), 'bio_data/' . $entity_id);
+      }
+      $ordered_items[ucfirst($type)][] = $name;
+    }
+
+    // Reorder the list so it's compatible with theming a list.
+    $list_items = array();
+    $headers = array();
+    $rows = array();
+    ksort($ordered_items);
+    foreach ($ordered_items as $type => $children) {
+      $rows[] = array(
+        array(
+          'data' => ucfirst($type) . '(s)',
+          'header' => TRUE,
+          'width' => '20%',
+        ),
+        theme_item_list(array(
+          'items' => $children,
+          'title' => '',
+          'type' => 'ul',
+          'attributes' => array(),
+        )),
+      );
+    }
+
+    $table = array(
+      'header' => array(),
+      'rows' => $rows,
+      'attributes' => array(
+        'id' => 'sio__references-table',
+        'class' => 'tripal-data-table'
+      ),
+      'sticky' => FALSE,
+      'caption' => "",
+      'colgroups' => array(),
+      'empty' => 'There are no records in this site to which this publiation refers.',
+    );
+    $content = theme_table($table);
+    $element[0] = array(
+      '#type' => 'markup',
+      '#markup' => $content,
+    );
+  }
+}

+ 27 - 0
tripal_chado/includes/TripalFields/sio__references/sio__references_widget.inc

@@ -0,0 +1,27 @@
+<?php
+
+class sio__references_widget extends ChadoFieldWidget {
+  // The default lable for this field.
+  public static $default_label = 'References';
+
+  // The list of field types for which this formatter is appropriate.
+  public static $field_types = array('sio__references');
+
+  /**
+   *
+   * @see TripalFieldWidget::form()
+   */
+  public function form(&$widget, &$form, &$form_state, $langcode, $items, $delta, $element) {
+    parent::form($widget, $form, $form_state, $langcode, $items, $delta, $element);
+
+
+  }
+
+  /**
+   *
+   * @see TripalFieldWidget::submit()
+   */
+  public function submit($form, &$form_state, $entity_type, $entity, $langcode, $delta) {
+
+  }
+}

+ 0 - 11
tripal_chado/includes/tripal_chado.bundle.inc

@@ -57,16 +57,5 @@ function tripal_chado_bundle_create($bundle, $storage_args) {
     if (!$success) {
       throw new Exception('Cannot create content type. Problem associating type with Chado.');
     }
-    $chado_bundle = db_select('chado_bundle', 'cb')
-      ->fields('cb')
-      ->condition('bundle_id', $bundle->id)
-      ->execute()
-      ->fetchObject();
   }
-
-  // Create/Add the new fields for this bundle.
-  tripal_chado_bundle_create_fields($entity_type, $bundle, $chado_bundle);
-
-  // Create/Add the new field instances for this bundle.
-  tripal_chado_bundle_create_instances($entity_type, $bundle, $chado_bundle);
 }

+ 69 - 28
tripal_chado/includes/tripal_chado.fields.inc

@@ -6,7 +6,13 @@
  * This is a Tripal defined hook that supports integration with the
  * TripalEntity field.
  */
-function tripal_chado_bundle_create_fields($entity_type, $bundle, $chado_bundle) {
+function tripal_chado_bundle_create_fields($entity_type, $bundle) {
+
+  $chado_bundle = db_select('chado_bundle', 'cb')
+    ->fields('cb')
+    ->condition('bundle_id', $bundle->id)
+    ->execute()
+    ->fetchObject();
 
   // Get the details about the mapping of this bundle to the Chado table:
   $details = array(
@@ -27,22 +33,8 @@ function tripal_chado_bundle_create_fields($entity_type, $bundle, $chado_bundle)
   // Create fields for linking tables.
   tripal_chado_bundle_create_fields_linker($info, $details, $entity_type, $bundle);
 
-  foreach ($info as $field_name => $details) {
-    $field_type = $details['type'];
-
-    // If the field already exists then skip it.
-    $field = field_info_field($details['field_name']);
-    if ($field) {
-      continue;
-    }
+  return $info;
 
-    // Create the field.
-    $field = field_create_field($details);
-    if (!$field) {
-      tripal_set_message(t("Could not create new field: %field.",
-          array('%field' =>  $details['field_name'])), TRIPAL_ERROR);
-    }
-  }
 }
 /**
  *
@@ -488,6 +480,23 @@ function tripal_chado_bundle_create_fields_linker(&$info, $details, $entity_type
     );
   }
 
+  // PUBLICATIONS (in reverse)
+  // We want to be able to show all of the content that a publication links
+  // to. The sio__references field does that.
+  if ($table_name == 'pub') {
+    $field_name = 'sio__references';
+    $field_type = 'sio__references';
+    $info[$field_name] =  array(
+      'field_name' => $field_name,
+      'type' => $field_type,
+      'cardinality' => FIELD_CARDINALITY_UNLIMITED,
+      'locked' => TRUE,
+      'storage' => array(
+        'type' => 'field_chado_storage',
+      ),
+    );
+  }
+
   // RELATIONSHIPS
   // If the linker table does not exists then we don't want to add attach.
   $rel_table = $table_name . '_relationship';
@@ -530,7 +539,13 @@ function tripal_chado_bundle_create_fields_linker(&$info, $details, $entity_type
  * This is a Tripal defined hook that supports integration with the
  * TripalEntity field.
  */
-function tripal_chado_bundle_create_instances($entity_type, $bundle, $chado_bundle) {
+function tripal_chado_bundle_create_instances($entity_type, $bundle) {
+
+  $chado_bundle = db_select('chado_bundle', 'cb')
+    ->fields('cb')
+    ->condition('bundle_id', $bundle->id)
+    ->execute()
+    ->fetchObject();
 
   $details = array(
     'chado_cvterm_id' => $chado_bundle->type_id,
@@ -543,17 +558,7 @@ function tripal_chado_bundle_create_instances($entity_type, $bundle, $chado_bund
   tripal_chado_bundle_create_instances_custom($info, $entity_type, $bundle, $details);
   tripal_chado_bundle_create_instances_linker($info, $entity_type, $bundle, $details);
 
-  foreach ($info as $field_name => $details) {
-    // If the field is already attached to this bundle then skip it.
-    $field = field_info_field($details['field_name']);
-    if ($field and array_key_exists('bundles', $field) and
-        array_key_exists('TripalEntity', $field['bundles']) and
-        in_array($bundle->name, $field['bundles']['TripalEntity'])) {
-      continue;
-    }
-    // Create the field instance.
-    $instance = field_create_instance($details);
-  }
+  return $info;
 
 }
 /**
@@ -1434,6 +1439,42 @@ function tripal_chado_bundle_create_instances_linker(&$info, $entity_type, $bund
     );
   }
 
+  // PUBLICATIONS (in reverse)
+  // We want to be able to show all of the content that a publication links
+  // to. The sio__references field does that.
+  if ($table_name == 'pub') {
+    $field_name = 'sio__references';
+    $schema = chado_get_schema($table_name);
+    $pkey = $schema['primary key'][0];
+    $info[$field_name] = array(
+      'field_name' => $field_name,
+      'entity_type' => $entity_type,
+      'bundle' => $bundle->name,
+      'label' => 'References',
+      'description' => 'Records that are referred to by the publication.',
+      'required' => FALSE,
+      'settings' => array(
+        'auto_attach' => FALSE,
+        'chado_table' => $table_name,
+        'chado_column' => $pkey,
+        'base_table' => $table_name,
+      ),
+      'widget' => array(
+        'type' => 'sio__references_widget',
+        'settings' => array(
+          'display_label' => 1,
+        ),
+      ),
+      'display' => array(
+        'default' => array(
+          'label' => 'above',
+          'type' => 'sio__references_formatter',
+          'settings' => array(),
+        ),
+      ),
+    );
+  }
+
   // RELATIONSHIPS
   // If the linker table does not exists then we don't want to add attach.
   $rel_table = $table_name . '_relationship';

+ 7 - 0
tripal_chado/includes/tripal_chado.semweb.inc

@@ -237,6 +237,13 @@ function tripal_chado_populate_vocab_SIO() {
     'cv_name' => 'SIO',
     'definition' => 'A clause consists of a subject and a predicate.',
   ));
+
+  $term = tripal_insert_cvterm(array(
+    'id' => 'SIO:000631',
+    'name' => 'references',
+    'cv_name' => 'SIO',
+    'definition' => 'references is a relation between one entity and the entity that it makes reference to by name, but is not described by it.',
+  ));
 }
 /**
  * Adds the EDAM database and terms.

+ 1 - 1
tripal_chado/tripal_chado.module

@@ -696,7 +696,7 @@ function tripal_chado_theme($existing, $type, $theme, $path) {
       if (!$mapped_table) {
         return;
       }
-      
+
       $chado_table = $mapped_table->chado_table;
       $legacy_template = 'legacy_template--chado_' . $chado_table;
       if (key_exists($legacy_template, $enabled_templates) && $enabled_templates[$legacy_template]) {