diff --git a/README.txt b/README.txt
deleted file mode 100644
index ed7d0fd..0000000
--- a/README.txt
+++ /dev/null
@@ -1,86 +0,0 @@
-Glossary helps newbies understand the jargon which always crops up when
-specialists talk about a topic. Doctors discuss CBC and EKG and CCs.
-Web developers keep talking about CSS, P2P, XSLT, etc. This is all
-intimidating for newbies.
-
-The most recent documentation on this module will be found at:
-http://drupal.org/node/196880
-
-The glossary module uses a filter that scans posts for glossary terms 
-(including synonyms). The glossary indicator is inserted after every
-found term, or the term itself is turned into an indicator depending
-on the site settings. By hovering over the indicator, users may learn
-the definition of that term. Clicking the indicator leads the user to
-that term presented within the whole glossary or directly to the
-detailed description of the term, if available.
-
-The glossary uses Drupal's built in taxonomy feature, so you can organize
-your terms in a Drupal vocabulary. This allows you to create hierarchical
-structures, synonyms and relations. Glossary terms are represented with
-the taxonomy terms in the glossary vocabulary. Descriptions are used to
-provide a short explanation of the terms. You can attach nodes to the
-terms to provide detailed explanation on the keywords.
-
-The Glossary module will call the Taxonomy Image module, if it's enabled,
-to allow you to display an image for each term in the glossary.
-
-If you use Firefox, you may want to install the "Longer Titles" add-on
-in order to see the entire definition.
-
-Installation
-------------
-
-1. Copy this whole folder to the appropriate modules/ directory, as usual.
-   Drupal should automatically detect the module. Enable the module on
-   the modules administration page.
-
-2. Glossary terms are managed as vocabularies within the taxonomy.module.
-   To get started with glossary, create a new vocabulary on the
-   taxonomy administration page. The vocabulary need not be associated
-   with any content types, though you can attach detailed description to terms
-   by adding nodes to the terms, so it might be a good idea to associate
-   the vocabulary with the "story" type. Add a few terms to the vocabulary.
-   The term title should be the glossary entry, the description should be
-   the explanation of that term. You can make use of the hierarchy,
-   synonym, and related terms features. These features impact the display
-   of the glossary when viewed in an overview. Synonyms will be flaggged in
-   the content the same way as the base term. Related terms will be linked
-   to each other.
-
-3. Next, you have to set up the module and the input formats you want to use.
-   This is done on the Glossary settings page at Administer >> Site configuration
-   >> Glossary. First select the appropriate "General" settings and save them.
-   Then select the tabs corresponding to any "input formats" you will allow to 
-   be used on your site (probably at least "Filtered HTML"). You may have
-   different settings for each input format, but consider that carefully. You
-   will be able to choose between superscript, icon, or acronym inclusion for
-   each term.
-
-4. If your language's alphabet consists of something other than A-Z, you will
-   need to enter the correct alphabet (in the correct order) on the "Alphabet"
-   settings page. You may blank out the digits section if you don't use terms
-   beginning with numbers.
-   
-5. If you want a search box on your glossary page, enable the block on admin/block page.
-
-
-Advanced Usage
---------------
-
-You can create a dedicated glossary for some pages of your site. To do so, create a new
-vocabulary and put the special terms in it. Then create a new input format and add the
-glossary filter to it. Then configure glossary filter in that format to look at the new
-vocabulary. Finally, affiliate the special pages with this input format and you will get
-the desired behavior.
-
-You may also set up a "dictionary" that looks just like the glossary page, but is not 
-associated with a vocabulary.
-
-Authors
--------
-Additional improvements and fixes by Nancy Wichmann
-More improvements by Moshe Weitzman aagin. And so it goes around ...
-More improvements by Frodo Looijaard <drupal [at] frodo.looijaard.name>
-Many improvements by Gábor Hojtsy <goba [at] php.net>
-Modified extensively by Al Maw <drupal-glossary [at] almaw.com>.
-Originally written by Moshe Weitzman <weitzman [at] tejasa.com>. Much help from killes.
diff --git a/TODO b/TODO
deleted file mode 100644
index 5b707be..0000000
--- a/TODO
+++ /dev/null
@@ -1,11 +0,0 @@
-; $Id$
-
-TODO:
-  
-- support a filter to emit a list of glossary terms used in a post (which might
-  be formatted as a sidebox in an article).
-
-- make another filter which discovers candidate glossary terms
-  (perhaps any sequence of 3 or more capital letters) and save those
-  in a table where the admin "promote" them to glossary term status and
-  give them definitions if they are in fact worthy of glossary status.
diff --git a/config/install/glossary.settings.yml b/config/install/glossary.settings.yml
new file mode 100644
index 0000000..cdcdd89
--- /dev/null
+++ b/config/install/glossary.settings.yml
@@ -0,0 +1,2 @@
+glossary_use_toggle_field: false
+glossary_vocabulary: 'glossary'
diff --git a/config/schema/glossary.schema.yml b/config/schema/glossary.schema.yml
new file mode 100644
index 0000000..7bae084
--- /dev/null
+++ b/config/schema/glossary.schema.yml
@@ -0,0 +1,10 @@
+glossary.filters:
+  type: filter
+  label: 'Glossary filter'
+  mapping:
+    glossary_use_toggle_field:
+      type: boolean
+      label: 'Use toggle field'
+    glossary_vocabulary:
+      type: string
+      label: 'Glossary vocabulary'
diff --git a/empty.gif b/empty.gif
deleted file mode 100644
index d943eb0..0000000
Binary files a/empty.gif and /dev/null differ
diff --git a/glossary.admin.inc b/glossary.admin.inc
deleted file mode 100644
index 935bf3f..0000000
--- a/glossary.admin.inc
+++ /dev/null
@@ -1,545 +0,0 @@
-<?php
-/**
- * @file
- * Glossary administration functions and forms.
- */
-
-/**
- *  This is the introductory stuff for the settings.
- */
-
-/**
- * Menu callback for settings.
- */
-function glossary_general_settings_form($form, &$form_state) {
-  $form = array();
-  drupal_add_js(drupal_get_path('module', 'glossary') . '/glossary.js');
-
-  $mb_status = extension_loaded('mbstring') ? t('enabled') : t('disabled');
-  $overload = ini_get('mbstring.func_overload') ? t('enabled') : t('disabled');
-  $mb = '<p>' . t('Multibyte string support is !status; multibyte function overload is !overload.',
-    array('!status' => $mb_status, '!overload' => $overload)) . '</p>';
-  $form['mb_stuff'] = array('#type' => 'markup', '#markup' => $mb);
-
-  $form['general'] = array(
-    '#type' => 'fieldset',
-    '#title' => t('General settings'),
-    '#collapsible' => TRUE,
-    '#collapsed' => FALSE,
-  );
-
-  $form['general']['glossary_disable_indicator'] = array(
-    '#type' => 'checkbox',
-    '#title' => t('Allow the user to disable glossary links.'),
-    '#default_value' => variable_get('glossary_disable_indicator', FALSE),
-    '#description' => t('Determines whether or not the individual user may disable the Glossary indicators.'),
-  );
-
-  $form['general']['glossary_hide_menus'] = array(
-    '#type' => 'checkbox',
-    '#title' => t('Hide unused text format tabs.'),
-    '#default_value' => variable_get('glossary_hide_menus', FALSE),
-    '#description' => t('Determines whether or not to hide settings tabs for text formats that are not glossary-enabled. Changing this setting may require you to clear the cache_menu table.'),
-  );
-
-  $click_options = array(
-    t('Show only the single term.'),
-    t('Advance the whole glossary to the term.'),
-  );
-  $form['general']['glossary_click_option'] = array(
-    '#type' => 'radios',
-    '#title' => t('Clicking on a term link will'),
-    '#options' => $click_options,
-    '#default_value' => variable_get('glossary_click_option', 0),
-    '#description' => t('Changing this setting may require you to clear the cache_filter.'),
-    '#attributes' => array('class' => array('container-inline')),
-  );
-
-  $form['general']['glossary_show_edit'] = array(
-    '#type' => 'checkbox',
-    '#title' => t('Show "edit" link.'),
-    '#default_value' => variable_get('glossary_show_edit', TRUE),
-    '#description' => t('Determines whether or not to show an "edit term" link for each entry.'),
-  );
-
-  $form['general']['glossary_show_search'] = array(
-    '#type' => 'checkbox',
-    '#title' => t('Show "search" link.'),
-    '#default_value' => variable_get('glossary_show_search', TRUE),
-    '#description' => t('Determines whether or not to show an "search for term" link for each entry.'),
-  );
-
-  $form['glossary_page'] = array(
-    '#type' => 'fieldset',
-    '#title' => t('Glossary Page'),
-    '#collapsible' => TRUE,
-    '#collapsed' => FALSE,
-  );
-
-  // This next setting cannot vary by format since the glossary overview doesn't
-  // care or know about text formats.
-  $form['glossary_page']['glossary_page_per_letter'] = array(
-    '#type' => 'checkbox',
-    '#title' => t('Show glossary across many smaller pages.'),
-    '#default_value' => variable_get('glossary_page_per_letter', FALSE),
-    '#description' => t('Do you want to show all terms on one glossary page or break up the glossary into a page for each first letter (i.e. many pages).'),
-  );
-
-  $form['glossary_page']['glossary_separate_letters'] = array(
-    '#type' => 'checkbox',
-    '#title' => t('Separate letters.'),
-    '#default_value' => variable_get('glossary_separate_letters', FALSE),
-    '#description' => t('Separate the terms by the first letters. This will create a large letter at the beginning of each section.'),
-  );
-
-  $form['glossary_page']['glossary_allow_no_description'] = array(
-    '#type' => 'checkbox',
-    '#title' => t('Show glossary terms even if there is no description.'),
-    '#default_value' => variable_get('glossary_allow_no_description', FALSE),
-    '#description' => t('By default, Glossary omits terms from the list if there is no term description. This setting overrides that. This is useful on free-tagging vocabularies that rarely get descriptions.'),
-  );
-
-  $form['glossary_page']['glossary_show_description'] = array(
-    '#type' => 'checkbox',
-    '#title' => t('Show glossary term descriptions on the Glossary page.'),
-    '#default_value' => variable_get('glossary_show_description', FALSE),
-    '#description' => t('Glossary term descriptions may be large and/or include pictures, therefore the Glossary page can take a long time to load if you include the full descriptions.'),
-  );
-
-  $form['glossary_page']['glossary_show_detailed'] = array(
-    '#type' => 'checkbox',
-    '#title' => t('Show detailed descriptions on the Glossary page.'),
-    '#default_value' => variable_get('glossary_show_detailed', FALSE),
-    '#description' => t('Glossary terms may have nodes associated with them. This option allows you to include the teasers of those nodes under the term.'),
-  );
-
-  $form['glossary_page']['glossary_link_related'] = array(
-    '#type' => 'checkbox',
-    '#title' => t('Link related terms on the Glossary page.'),
-    '#default_value' => variable_get('glossary_link_related', TRUE),
-    '#description' => t('Do you want terms that are related to link to each other? The type of link is determined by "Clicking on a term link will" above.'),
-  );
-
-  $form['glossary_page']['glossary_link_related_how'] = array(
-    '#type' => 'checkbox',
-    '#title' => t('Related terms link one-way.'),
-    '#default_value' => variable_get('glossary_link_related_how', FALSE),
-    '#description' => t('By default, links are two way, that is if "a" is related to "b" then "b" is also related to "a". This option changes that so that "b" points to "a" only if it is set explicitly for the term. Requires "Link related" above to be selected.'),
-    '#prefix' => '<div class="glossary_link_related_how">',
-    '#suffix' => '</div>',
-  );
-
-  $form['glossary_page']['glossary_term_class'] = array(
-    '#type' => 'textfield',
-    '#title' => t('Term link class'),
-    '#default_value' => variable_get('glossary_term_class', 'glossary-term'),
-    '#description' => t('This is the style class that will be used for "acronym," "abbr," and "hovertip" links. It should only be used by those with specific site standards.'),
-  );
-
-  global $user;
-  $format_list = filter_formats($user);
-  $formats = array(filter_default_format() => '-default-');
-  foreach ($format_list as $number => $filter) {
-    $formats[$number] = $filter->name;
-  }
-  $form['glossary_page']['glossary_default_filter'] = array(
-    '#type' => 'radios',
-    '#options' => $formats,
-    '#title' => t('Default text format'),
-    '#default_value' => variable_get('glossary_default_filter', filter_default_format()),
-    '#description' => t('This will be used as the default text format.'),
-    '#attributes' => array('class' => array('container-inline')),
-  );
-
-  return system_settings_form($form);
-}
-
-/**
- * This is the form for the getting the user's alphabet for the alphabar.
- * @todo Please document this function.
- * @see http://drupal.org/node/1354
- */
-function glossary_alphabet_form($form, &$form_state) {
-  global $language;
-  $form = array();
-
-  $form['alphabet'] = array(
-    '#type' => 'textarea',
-    '#title' => t('Enter all the letters of your alphabet, in the correct order, and in lower case.'),
-    '#default_value' => implode(' ', variable_get('glossary_alphabet', range('a', 'z'))),
-    '#description' => t('Separate the letters by a blank.'),
-    '#rows' => 1,
-  );
-
-  $form['digits'] = array(
-    '#type' => 'textarea',
-    '#title' => t('Enter all the digits of your alphabet, in the correct order.'),
-    '#default_value' => implode(' ', variable_get('glossary_digits', range('0', '9'))),
-    '#description' => t("Separate the digits by a blank. If you don't want terms to start with digits, leave this blank."),
-    '#rows' => 1,
-  );
-
-  $form['suppress_unused'] = array(
-    '#type' => 'checkbox',
-    '#title' => t('Suppress unused letters?'),
-    '#default_value' => variable_get('glossary_suppress_unused', FALSE),
-    '#description' => t('This will cause unused letters to be omitted from the alphabar.'),
-  );
-
-  $ab_seps = array(
-    ' ' => t('&lt;none>'),
-    '|' => t('vertical bar (pipe)'),
-    '&bull;' => t('bullet'),
-    '&#8211;' => t('en-dash (&#8211;)'),
-    '&#8212;' => t('em-dash (&#8212;)'),
-    '_' => t('underscore'),
-  );
-  $form['alphabar_separator'] = array(
-    '#type' => 'radios',
-    '#options' => $ab_seps,
-    '#title' => t('Alphabar separator'),
-    '#default_value' => variable_get('glossary_alphabar_separator', '|'),
-    '#description' => t('This is the character that will separate the letters in the alphabar.'),
-    '#attributes' => array('class' => array('container-inline')),
-  );
-
-  $form['alphabar_instruction'] = array(
-    '#type' => 'textarea',
-    '#title' => t('Alphabar instruction'),
-    '#default_value' => variable_get('glossary_alphabar_instruction', _alphabar_instruction_default()),
-    '#description' => t('This is the text that will appear immediately below the alphabar. HTML may not be rendered correctly.'),
-    '#rows' => 1,
-  );
-
-  $form['submit'] = array(
-    '#type' => 'submit',
-    '#value' => t('Save configuration'),
-    '#weight' => 5,
-  );
-
-  return $form;
-}
-
-/**
- * This is validator for user's alphabet for the alphabar form.
- * @todo Please document this function.
- * @see http://drupal.org/node/1354
- */
-function glossary_alphabet_form_validate($form, &$form_state) {
-  if (strip_tags($form_state['values']['alphabet']) != $form_state['values']['alphabet']) {
-    form_set_error('alphabet', t('Invalid characters in the alphabet.'));
-  }
-  if (strip_tags($form_state['values']['digits']) != $form_state['values']['digits']) {
-    form_set_error('digits', t('Invalid characters in the digits.'));
-  }
-}
-
-/**
- * Form submission handler for the alphabar.
- */
-function glossary_alphabet_form_submit($form, &$form_state) {
-  variable_set('glossary_alphabet', explode(' ', $form_state['values']['alphabet']));
-  if ($form_state['values']['digits']) {
-    variable_set('glossary_digits', explode(' ', $form_state['values']['digits']));
-  }
-  else {
-    variable_set('glossary_digits', array());
-  }
-  variable_set('glossary_suppress_unused', $form_state['values']['suppress_unused']);
-  variable_set('glossary_alphabar_separator', $form_state['values']['alphabar_separator']);
-  variable_set('glossary_alphabar_instruction', $form_state['values']['alphabar_instruction']);
-
-  drupal_set_message(t('Configuration saved'), 'status');
-}
-
-/**
- * This is the form for the settings for an individual text format.
- */
-function glossary_filter_form($form, $form_state, $format = 1, $x = NULL) {
-  drupal_add_js(drupal_get_path('module', 'glossary') . '/glossary.js');
-
-  $form = array();
-
-  drupal_add_js(drupal_get_path('module', 'glossary') . '/glossary.js');
-
-  $options = array();
-  $result = db_query('SELECT vid, name FROM {taxonomy_vocabulary} ORDER BY name');
-  foreach ($result as $vocabulary) {
-    $options[$vocabulary->vid] = filter_xss_admin($vocabulary->name);
-  }
-
-  if (!$options) {
-    drupal_set_message(t('No vocabularies were found. Until you set up, and select, at least one vocabulary for Glossary, no substitutions can be done.'));
-  }
-
-  // Make sure we know if we need to clear the cache.
-  variable_del('glossary_need_to_clear_cache', TRUE);
-
-  // Get information about this filter.
-  $filter = db_query('SELECT * FROM {filter_format} WHERE format = :format', array(':format' => $format))->fetchAssoc();
-
-  // See if we are enabled for this text format.
-  $enabled = db_query("SELECT COUNT(*) FROM {filter} WHERE format = :format AND module = :module",
-    array(':format' => $format, ':module' => 'glossary'))->fetchField();
-  if ($enabled) {
-    $enabled_msg = NULL;
-  }
-  else {
-    $enabled_msg = '<p><big>' . t('The Glossary module is not enabled for this text format. <a href="!url">Change the settings</a>.', array('!url' => url('admin/config/content/formats/' . $format))) . '</big></p>';
-  }
-
-  if ($filter['cache']) {
-    $cache_msg = t('This filter may be cached.');
-
-    // Is there anything in the cache now?
-    // We can't use cache_get because we would need the md5 hash of the text.
-    // TODO Please convert this statement to the D7 database API syntax.
-    $cached_content = db_query("SELECT COUNT(cid) FROM {cache_filter} WHERE cid LIKE ('%:format%')",
-      array(':format' => $format))->fetchField();
-    if ($cached_content == 0) {
-      $cache_exist = FALSE;
-    }
-    else {
-      $cache_exist = TRUE;
-      $cache_msg .= ' ' . t('There is currently cached data for this text format.');
-    }
-    $cache_lifetime = variable_get('cache_lifetime', 0);
-    if ($cache_lifetime) {
-      $cache_msg .= ' ' . t('You are using a minimum cache lifetime of !life.', array('!life' => format_interval($cache_lifetime, 1)));
-    }
-    else {
-      $cache_msg .= ' ' . t('You do not have a minimum cache lifetime.');
-    }
-  }
-  else {
-    $cache_msg = t('This filter may not be cached.');
-  }
-
-  $form['format'] = array(
-    '#type' => 'value',
-    '#value' => $format,
-  );
-
-  $form['filter'] = array(
-    '#type' => 'fieldset',
-    '#title' => t('text format settings'),
-    '#collapsible' => TRUE,
-    '#collapsed' => FALSE,
-    '#description' => $enabled_msg . $cache_msg
-    . '<br/>' . t('Submitting this form will clear the "cache_filter" table, which will have a short-term performance impact.'),
-  );
-
-  if (!$enabled) {
-    return $form;
-  }
-
-  $form['filter']["glossary_vids_$format"] = array(
-    // <--- has a problem with "<none>".
-    '#type' => 'checkboxes',
-    '#title' => t('Select Vocabulary'),
-    '#default_value' => variable_get("glossary_vids_$format", array()),
-    '#options' => $options,
-    '#description' => t('Select one or more vocabularies which hold all terms for your glossary. When enabled, posts will be scanned for glossary terms from the selected vocabulary(ies) and an icon or link will be inserted for each term. Choosing no vocabularies will result in no terms being flagged.'),
-    '#multiple' => TRUE,
-    '#required' => FALSE,
-    '#attributes' => array('class' => array('container-inline')),
-  );
-
-  $form['filter']['match'] = array(
-    '#type' => 'fieldset',
-    '#title' => t('Term matching'),
-    '#collapsible' => TRUE,
-    '#collapsed' => FALSE,
-  );
-
-  $form['filter']['match']["glossary_match_$format"] = array(
-    '#type' => 'radios',
-    '#title' => t('Match type'),
-    '#default_value' => variable_get("glossary_match_$format", 'b'),
-    '#options' => array(
-      'b' => t('Word'),
-      'lr' => t('Right or left substring'),
-      'l' => t('Left substring'),
-      'r' => t('Right substring'),
-      's' => t('Any substring'),
-    ),
-    '#description' => t('Choose the match type of glossary links. "Word" means a word break must occur on both sides of the term. "Right or left" requires a word break on either side. "Left" requires a word break on the left side of the term. "Right" requires a word break on the right. "Any" means any substring will match.'),
-    '#attributes' => array('class' => array('container-inline')),
-  );
-
-  $form['filter']['match']["glossary_case_$format"] = array(
-    '#type' => 'radios',
-    '#title' => t('Case sensitivity'),
-    '#default_value' => variable_get("glossary_case_$format", '1'),
-    '#options' => array(
-      t('Case insensitive'),
-      t('Case sensitive'),
-    ),
-    '#description' => t('Match either case sensitive or not. Case sensitive matches are not very resource intensive.'),
-    '#attributes' => array('class' => array('container-inline')),
-  );
-
-  $form['filter']['match']["glossary_replace_all_$format"] = array(
-    '#type' => 'radios',
-    '#title' => t('Replace matches'),
-    '#default_value' => variable_get("glossary_replace_all_$format", 0),
-    '#options' => array(
-      t('Only the first match'),
-      t('All matches'),
-    ),
-    '#description' => t('Whether only the first match should be replaced or all matches.'),
-    '#attributes' => array('class' => array('container-inline')),
-  );
-
-  $form['filter']['match']["glossary_blocking_tags_$format"] = array(
-    '#type' => 'textarea',
-    '#title' => t('Blocked elements'),
-    '#default_value' => variable_get("glossary_blocking_tags_$format", 'abbr acronym'),
-    '#cols' => 60,
-    '#rows' => 1,
-    '#maxlength' => 512,
-    '#description' => t('Which HTML elements (tags) should not include Glossary links;
-      that is, text within these elements will not be scanned for glossary terms.
-      Enter the list separated by a space and do not include < and > characters (e.g. h1 h2).
-      To use a %span element to skip text, prefix the class name with a dot (e.g. ".skipping-this").
-      All "a," "code," and "pre" elements will be skipped by default.
-      ', array('%span' => 'span')),
-  );
-
-  $form['filter']['indicator'] = array(
-    '#type' => 'fieldset',
-    '#title' => t('Link style'),
-    '#collapsible' => TRUE,
-    '#collapsed' => FALSE,
-  );
-
-  $form['filter']['indicator']["glossary_link_$format"] = array(
-    '#type' => 'radios',
-    '#options' => array(
-      'none' => t('none'),
-      'normal' => t('normal'),
-      'absolute' => t('absolute'),
-    ),
-    '#title' => t('Link type'),
-    '#default_value' => variable_get("glossary_link_$format", 'normal'),
-    '#description' => t('You may choose no linking of terms ("none"), standard site linking ("normal"), or "absolute" links. RSS feeds need absolute links to ensure they point back to this site. If you are not providing RSS feeds, it is better to choose one of the other types.'),
-    '#attributes' => array('class' => array('container-inline')),
-  );
-
-  $indicator_options = array(
-    'superscript' => t('Superscript'),
-    'icon' => t('Icon'),
-    'iconterm' => t('Icon + Term'),
-    'abbr' => t('Use !type element', array(
-      '!type' => l(t('abbr'), 'http://www.w3.org/TR/html401/struct/text.html#edef-ABBR'))
-    ),
-    'acronym' => t('Use !type element', array(
-      '!type' => l(t('acronym'), 'http://www.w3.org/TR/html401/struct/text.html#edef-ACRONYM'))
-    ),
-    'cite' => t('Use !type element', array(
-      '!type' => l(t('cite'), 'http://www.w3.org/TR/html401/struct/text.html#edef-CITE'))
-    ),
-    'dfn' => t('Use !type element', array(
-      '!type' => l(t('dfn'), 'http://www.w3.org/TR/html401/struct/text.html#edef-DFN'))
-    ),
-  );
-
-  if (module_exists('hovertip')) {
-    $indicator_options['hovertip'] = t('Hovertip');
-    $indicator_options['clicktip'] = t('Clicktip');
-  }
-
-  $form['filter']['indicator']['glossary_replace'] = array(
-    '#type' => 'radios',
-    '#title' => t('Term Indicator'),
-    '#default_value' => variable_get("glossary_replace_$format", 'superscript'),
-    '#options' => $indicator_options,
-    '#description' => t('This determines how the link to the glossary term will be indicated. The "phrase" items are linked to the standards in case you want to study them.'),
-    '#validate' => array('glossary_indicator_intercept' => array()),
-    '#attributes' => array('class' => array('container-inline')),
-  );
-
-  $form['filter']['indicator']["glossary_superscript"] = array(
-    '#type' => 'textfield',
-    '#title' => t('Superscript'),
-    '#default_value' => variable_get("glossary_superscript_$format", 'i'),
-    '#size' => 15,
-    '#maxlength' => 255,
-    '#description' => t('If you chose "superscript" above, enter the superscript text.'),
-    '#validate' => array('glossary_indicator_intercept' => array()),
-    '#prefix' => '<div class="glossary_superscript">',
-    '#suffix' => '</div>',
-  );
-
-  $mypath = base_path() . drupal_get_path('module', 'glossary');
-  $form['filter']['indicator']["glossary_icon"] = array(
-    '#type' => 'textfield',
-    '#title' => t('Glossary Icon URL'),
-    '#default_value' => variable_get("glossary_icon_$format", $mypath . '/glossary.gif'),
-    '#size' => 50,
-    '#maxlength' => 255,
-    '#description' => t('If you chose "icon" above, enter the URL of the glossary icon relative to the root ("%root") of your Drupal site.', array('%root' => base_path())),
-    '#prefix' => '<div class="glossary_icon">',
-    '#suffix' => '</div>',
-  );
-
-  $form['submit'] = array(
-    '#type' => 'submit',
-    '#value' => t('Save configuration'),
-    '#weight' => 5,
-  );
-
-  return $form;
-}
-
-/**
- * This is filter for submit handler.
- * @todo Please document this function.
- * @see http://drupal.org/node/1354
- */
-function glossary_filter_form_submit($form, &$form_state) {
-  $format = $form_state['values']['format'];
-  _glossary_clear_cache($format);
-
-  $vids_name = "glossary_vids_$format";
-  $link_name = "glossary_link_$format";
-  $match_name = "glossary_match_$format";
-  $case_name = "glossary_case_$format";
-  $replace_all_name = "glossary_replace_all_$format";
-  $blocking_tags_name = "glossary_blocking_tags_$format";
-  foreach ($form_state['values'][$vids_name] as $vid => $value) {
-    if ($value == 0) {
-      unset($form_state['values'][$vids_name][$vid]);
-    }
-  }
-  variable_set($vids_name, $form_state['values'][$vids_name]);
-  variable_set($link_name, $form_state['values'][$link_name]);
-  variable_set($match_name, $form_state['values'][$match_name]);
-  variable_set($case_name, $form_state['values'][$case_name]);
-  variable_set($replace_all_name, $form_state['values'][$replace_all_name]);
-  variable_set($blocking_tags_name, $form_state['values'][$blocking_tags_name]);
-  variable_set("glossary_replace_$format", $form_state['values']['glossary_replace']);
-  variable_set("glossary_superscript_$format", $form_state['values']["glossary_superscript"]);
-  variable_set("glossary_icon_$format", $form_state['values']["glossary_icon"]);
-  drupal_set_message(t('Configuration has been updated.'));
-}
-
-/**
- * Menu call back for clear cache button on settings page.
- * @todo Please document this function.
- * @see http://drupal.org/node/1354
- */
-function glossary_clearcache_form($form, &$form_state) {
-  $form = array();
-  $form['text'] = array(
-    '#type' => 'item',	
-    '#description' => t('This clears only the cache_filter table. To clear all cached data, you may use the button on the <a href="!url">Performance settings</a> page.', array('!url' => url('admin/config/development/performance'))),
-  );
-  $form['submit'] = array(
-    '#type' => 'submit',
-    '#value' => t('Clear cache'),
-  );
-  $form['#submit'][] = '_glossary_clear_cache';
-
-  return $form;
-}
diff --git a/glossary.css b/glossary.css
deleted file mode 100644
index ce8cd3d..0000000
--- a/glossary.css
+++ /dev/null
@@ -1,249 +0,0 @@
-
-abbr.glossary-indicator,
-acronym.glossary-indicator,
-sup.glossary-indicator,
-span.glossary-indicator,
-a.glossary-indicator,
-a.glossary-icon,
-dfn.glossary-indicator,
-img.glossary-indicator {
-  cursor: help;
-}
-
-span.glossary-term {
-  text-decoration: none;
-  border-bottom: 1px dotted;
-  cursor: help;
-}
-
-a.glossary-term {
-  text-decoration: none;
-  border-bottom: 1px dotted #080;
-  color: #080;
-  cursor: help;
-}
-
-dl.glossary-list > dt {
-  font-weight: bold;
-}
-
-dl.glossary-list > dd {
-  font-weight: normal;
-  font-size: 75%;
-  margin-left: 15px;
-}
-
-dl.glossary-list dt.depth1 {
-  padding-left: 10px;
-}
-
-dl.glossary-list dt.depth2 {
-  padding-left: 20px;
-}
-
-dl.glossary-list dt.depth3 {
-  padding-left: 30px;
-}
-
-.glossary-list dt {
-  padding-top: 7px;
-  clear: both;
-}
-
-td.glossary-list-description {
-  padding-left: 1em !important;
-  font-style: italic;
-  font-size: 90%;
-}
-
-a.glossary-edit-term {
-  font-size: 75%;
-  font-weight: normal;
-  margin-left: 2.0em;
-}
-
-a.glossary-search-term {
-  font-size: 75%;
-  font-weight: normal;
-  margin-left: 2.0em;
-}
-
-p.glossary-description {
-  margin: 0px 2.0em 0.5em 2.0em;
-  text-indent: 0;
-}
-
-div.glossary-letter {
-  clear: both;
-  text-align: center;
-  font-size: 150%;
-  font-weight: bold;
-  text-transform: uppercase;
-}
-
-.glossary-synonyms {
-  font-style: italic;
-  color: #888888;
-  margin-left: 1em;
-}
-
-.glossary-related {
-  font-style: italic;
-  color: green;
-  margin-left: 6px;
-}
-
-.glossary-related a {
-  text-decoration: underline;
-  color: green;
-}
-
-.glossary-related a:visited {
-  text-decoration: underline;
-  color: green;
-}
-
-.glossary-related a:link {
-  text-decoration: underline;
-  color: green;
-}
-
-.glossary-links {
-  text-align: center;
-  background-color: #eeeeff;
-  color: #888888;
-}
-
-.glossary-links a {
-  font-size: 140%;
-  text-transform: uppercase;
-}
-
-.glossary-alphabar-instructions {
-  font-size: 89%;
-  font-style: italic;
-}
-
-.glossary-admin-links {
-  clear: both;
-  margin: 0.5em 0 0 3.0em;
-}
-
-.glossary-admin-links li a {
-  padding: 5px;
-}
-
-.glossary-list dt img {
-  float: left;
-}  
-
-.glossary-list .taxonomy_image_wrapper {
-  width: 70px;
-  float: left;
-}
-
-a.clicktip_target {
-  font-style:normal;
-  /*border-bottom: 3px double #992222;*/
-}
-
-span.clicktip_target {
-  font-style:normal;
-}
-
-html > body .hovertip_wrap3 {
-  background-color: #ffdab9;
-  border: 3px outset #d2691e;
-}
-
-.hovertip h2 {
-  margin: 0;
-  padding: 0;
-  background-color: #D2691E;
-  color: #ffffff;
-}
-
-a.hovertip_target {
-  font-style:normal;
-  border-bottom: 3px double #992222;
-}
-
-span.hovertip_target {
-  font-style:normal;
-  border-bottom: 3px double #992222;
-}
-
-.glossary_radios .form-radios {
-  margin-top: 0;
-}
-
-.glossary_radios .form-item {
-  margin-top: 0;
-  margin-bottom: 0;
-}
-
-.glossary_checkboxes .form-checkboxes {
-  margin-top: 0;
-}
-
-.glossary_checkboxes .form-item {
-  margin-top: 0;
-  margin-bottom: 0;
-}
-
-.glossary_radios label.option {
-  margin-right: 1em;
-  border: 1px dotted #666666;
-  padding: 0 4px 1px 0;
-}
-
-.glossary_radios .form-item .description {
-  clear: both;
-}
-
-.glossary_checkboxes label.option {
-  margin-right: 1em;
-  float: left;
-  /* background: #ffffff; */
-  padding: 0 4px 1px 0;
-}
-
-.glossary_checkboxes .form-item .description {
-  clear: both; 
-}
-
-.glossary-detailed {
-  /* clear: both; */
-}
-
-.glossary-detailed h2 {
-  margin-left: 10px;
-}
-
-.glossary-detailed legend {
-  text-indent: 0;
-}
-
-.glossary-detailed-link {
-  font-size: 89%;
-  text-indent: 2em;
-}
-
-.glossary-interval .description {
-  display: block;
-}
-
-.block-glossary {
-  font-size: 89%;
-}
-
-.glossary-block-term-name {
-  font-weight: bold;
-  font-size: 110%;
-  text-align: center;
-}
-
-span.hovertip img {
-  text-align: left;
-  margin-right: 5px;
-}
diff --git a/glossary.gif b/glossary.gif
deleted file mode 100644
index 1f0d6e5..0000000
Binary files a/glossary.gif and /dev/null differ
diff --git a/glossary.info b/glossary.info
deleted file mode 100644
index a052850..0000000
--- a/glossary.info
+++ /dev/null
@@ -1,5 +0,0 @@
-name = Glossary
-description = Maintain a glossary on your site.
-core = 7.x
-dependencies[] = taxonomy
-files[] = glossary>admin.inc
diff --git a/glossary.info.yml b/glossary.info.yml
new file mode 100644
index 0000000..e5116fb
--- /dev/null
+++ b/glossary.info.yml
@@ -0,0 +1,6 @@
+name: Glossary
+type: module
+description: Provides a simple taxonomy based glossary.
+core: 8.x
+dependencies:
+  - filter
diff --git a/glossary.install b/glossary.install
deleted file mode 100644
index 3e60b4b..0000000
--- a/glossary.install
+++ /dev/null
@@ -1,117 +0,0 @@
-<?php
-
-/**
- * @file
- * Glossary module installation functions.
- */
-
-/**
- * Implements hook__update_last_removed().
- */
-function glossary__update_last_removed() {
-  return 6101;
-}
-
-/**
- * Implements hook_requirements().
- */
-function glossary_requirements($phase) {
-  $requirements = array();
-  // Ensure translations don't break at install time.
-  $t = get_t();
-
-  // Check that php is compiled with ctype support.
-  $requirements['ctype'] = array(
-    'title' => $t('Character type functions (ctype)'),
-  );
-  if (function_exists('ctype_alnum')) {
-    $requirements['ctype']['value'] = $t('Enabled');
-    $requirements['ctype']['severity'] = REQUIREMENT_OK;
-  }
-  else {
-    $requirements['ctype']['value'] = $t('Disabled');
-    $requirements['ctype']['description'] = $t('The Glossary module requires that you configure PHP with --enable-ctype.');
-    $requirements['ctype']['severity'] = REQUIREMENT_ERROR;
-  }
-
-  return $requirements;
-}
-
-/**
- * Implements hook_install().
- */
-function glossary_install() {
-  // Set all possible variables.In order to make sure all defaults are
-  // consistent, we'll just go ahead and set them all.
-  $mypath = '/' . drupal_get_path('module', 'glossary') . '/glossary.gif';
-
-  $filters = db_select('SELECT format FROM {filter_format}');
-  foreach ($filters as $format) {
-    variable_set('glossary_case_' . $format, 1);
-    variable_set('glossary_icon_' . $format, $mypath);
-    variable_set('glossary_match_' . $format, 'b');
-    variable_set('glossary_replace_' . $format, 'superscript');
-    variable_set('glossary_replace_all_' . $format, 0);
-    variable_set('glossary_superscript_' . $format, 'i');
-    variable_set('glossary_link_' . $format, FALSE);
-    variable_set('glossary_vids_' . $format, array());
-    variable_set('glossary_blocking_tags_' . $format, 'abbr acronym');
-  }
-
-  variable_set('glossary_page_per_letter', FALSE);
-  variable_set('glossary_disable_indicator', FALSE);
-  variable_set('glossary_click_option', 0);
-  variable_set('glossary_allow_no_description', FALSE);
-  variable_set('glossary_alphabet', range('a', 'z'));
-  variable_set('glossary_digits', range('0', '9'));
-  variable_set('glossary_hide_menus', FALSE);
-  variable_set('glossary_show_description', FALSE);
-  variable_set('glossary_suppress_unused', FALSE);
-  variable_set('glossary_alphabar_separator', '|');
-  variable_set('glossary_separate_letters', FALSE);
-
-  $t = get_t();
-  drupal_set_message($t('The Glossary module has been installed with default settings. To change the settings, !settings_uri.', array('!settings_uri' => l($t('Click Here'), 'admin/config/content/glossary'))));
-}
-
-/**
- * Implements of hook_uninstall().
- */
-function glossary_uninstall() {
-  // Delete all possible variables. Even if some don't exist,
-  // there is no harm in trying.It is left to the user to dispose of any
-  // vocabularies that are no longer needed.
-  $filters = db_select('SELECT format FROM {filter_format}');
-  foreach ($filters as $format) {
-    variable_del('glossary_case_' . $format);
-    variable_del('glossary_icon_' . $format);
-    variable_del('glossary_match_' . $format);
-    variable_del('glossary_replace_' . $format);
-    variable_del('glossary_replace_all_' . $format);
-    variable_del('glossary_superscript_' . $format);
-    variable_del('glossary_absolute_' . $format);
-    variable_del('glossary_vids_' . $format);
-    variable_del('glossary_blocking_tags_' . $format);
-  }
-  variable_del('glossary_page_per_letter');
-  variable_del('glossary_disable_indicator');
-  variable_del('glossary_need_to_clear_cache');
-  variable_del('glossary_click_option');
-  variable_del('glossary_allow_no_description');
-  variable_del('glossary_alphabet');
-  variable_del('glossary_digits');
-  variable_del('glossary_hide_menus');
-  variable_del('glossary_show_description');
-  variable_del('glossary_suppress_unused');
-  variable_del('glossary_alphabar_separator');
-  variable_del('glossary_block_1_interval');
-  variable_del('glossary_block_1_last');
-  variable_del('glossary_block_1_step');
-  variable_del('glossary_block_1_tid');
-  variable_del('glossary_block_1_vids');
-
-  // Let's make sure the filter cache is cleared of our stuff.
-  cache_clear_all(NULL, 'cache_filter');
-
-  drupal_set_message(t('The Glossary module has been uninstalled. You will still need to decide what to do with vocabularies that were used.'), 'warning');
-}
diff --git a/glossary.js b/glossary.js
deleted file mode 100644
index 0b43e20..0000000
--- a/glossary.js
+++ /dev/null
@@ -1,43 +0,0 @@
-
-function glossary_replace_handler(event) {
-  // Disable superscript field if not selected.
-  if ($("input[@name=glossary_replace]:checked").val() == 'superscript') {
-    $("input[@name=glossary_superscript]").parents("div.glossary_superscript").show();
-  }
-  else {
-    $("input[@name=glossary_superscript]").parents("div.glossary_superscript").hide();
-  }
-
-  // Disable icon URL field if not selected.
-  var selected = $("input[@name=glossary_replace]:checked").val();
-  if (selected == 'icon' || selected == 'iconterm') {
-    $("input[@name=glossary_icon]").parents("div.glossary_icon").show();
-  }
-  else {
-    $("input[@name=glossary_icon]").parents("div.glossary_icon").hide();;
-  }
-}
-
-function glossary_link_related_handler(event) {
-  // Disable one-way field if not selected.
-  if ($("input[@name=glossary_link_related]:checked").val() == 1) {
-    $("input[@name=glossary_link_related_how]").parents("div.glossary_link_related_how").show();
-  }
-  else {
-    $("input[@name=glossary_link_related_how]").val(0);
-    $("input[@name=glossary_link_related_how]").parents("div.glossary_link_related_how").hide();
-  }
-}
-
-// Run the javascript on page load.
-if (Drupal.jsEnabled) {
-  $(document).ready(function () {
-  // On page load, determine the current settings.
-  glossary_replace_handler();
-  glossary_link_related_handler();
-
-  // Bind the functions to click events.
-  $("input[@name=glossary_replace]").bind("click", glossary_replace_handler);
-  $("input[@name=glossary_link_related]").bind("click", glossary_link_related_handler);
-  });
-}
\ No newline at end of file
diff --git a/glossary.module b/glossary.module
index 58c9537..9214e43 100644
--- a/glossary.module
+++ b/glossary.module
@@ -2,1446 +2,23 @@
 
 /**
  * @file
- * Glossary terms will be automatically marked with links to their descriptions.
+ * Contains glossary.module.
  */
 
-/**
- * Implements hook_help().
- */
-function glossary_help($path, $args = array()) {
-  $output = '';
-
-  switch ($path) {
-    case 'admin/help#glossary':
-      return t('<p>Glossary helps newbies understand the jargon which always crops up when specialists talk about a topic. Doctors discuss CBC and EKG and CCs. Web developers keep talking about CSS, P2P, XSLT, etc. This is all intimidating for newbies.</p>
-      <p>The Glossary module scans posts for glossary terms in the body. If found, the glossary indicator is inserted after the term, or the term is turned into an indicator link depending on the settings. By hovering over the indicator, users may learn the definition of that term. Clicking leads the user to that term presented within the whole glossary.</p>
-      <p>Glossary terms are managed as vocabularies within the taxonomy.module. To get started with glossary, create a new vocabulary on the !taxonomy_admin page. The vocabulary need not be associated with any modules, although you can add detailed description to terms by attaching (story or other type of) nodes to them. Add a few terms to the vocabulary. The term title should be the glossary entry and the description should be its definition. You can make use of the hierarchy and related terms features. These features impact the display of the glossary when viewed in an overview.</p>
-      <p>Next, you have to set up the input formats with which you want to use the glossary. On the !input_formats page, select an input format to configure. Select the Glossary filter checkbox and press "Save configuration". Now proceed to the !glossary page and select the tab for the input format and select the vocabulary and other settings.</p>
-      <p>You can see how a vocabulary would function as a glossary by going to the !glossaries page and selecting the vocabulary to view.</p>
-      <p>Administration of glossary requires %permissions permissions.</p>', array(
-        '%permissions' => implode(', ', array(
-          t('administer taxonomy'),
-          t('access administration pages'),
-          t('administer filters'))
-        ),
-        '!taxonomy_admin' => l(t('administer >> content >> taxonomy'), 'admin/structure/taxonomy'),
-        '!input_formats' => l(t('administer >> site configuration >> input formats'), 'admin/config/content/formats'),
-        '!glossary' => l(t('administer >> site configuration >> glossary'), 'admin/config/content/glossary'),
-        '!glossaries' => l(t('glossaries'), 'glossary'),
-      ));
-
-    case 'admin/config/content/glossary':
-      return '<p><big>' . t('This page and its tabs allow you to control how the Glossary module functions.') . '</big></p>';
-
-    case 'admin/modules#description':
-      return t('Maintain one or more glossaries on your site.');
-
-    case 'glossary':
-      if (!$args[1]) {
-        if (user_access('administer filters')) {
-          return t('<a href="!url">Glossary settings page</a>', array('!url' => url('admin/config/content/glossary')));
-        }
-      }
-      break;
-
-    case 'glossary_search#noresults':
-      return t('<ul>
-      <li>Check if your spelling is correct.</li>
-      <li>Remove quotes around phrases to match each word individually: <em>"blue smurf"</em> will match less than <em>blue smurf</em>.</li>
-      <li>Consider loosening your query with <em>OR</em>: <em>blue smurf</em> will match less than <em>blue OR smurf</em>.</li>
-      </ul>');
-  }
-}
-
-/**
- * Implements hook_menu().
- */
-function glossary_menu() {
-  $items = array();
-
-  $items['glossary'] = array(
-    'title' => 'Glossary',
-    'page callback' => 'glossary_page',
-    'page arguments' => array(1, 2),
-    'access arguments' => array('access glossary'),
-    'type' => MENU_SUGGESTED_ITEM,
-  );
-
-  $items['glossary/search'] = array(
-    'title' => 'Glossary Search',
-    'page callback' => 'glossary_search_results',
-    'page arguments' => array(2),
-    'access arguments' => array('access glossary'),
-    'type' => MENU_CALLBACK,
-  );
-
-  $items['glossary/clearcache'] = array(
-    'title' => 'Glossary clear cache',
-    'page callback' => 'glossary_clearcache',
-    'access arguments' => array('administer filters'),
-    'type' => MENU_CALLBACK,
-  );
-
-  $items['admin/config/content/glossary'] = array(
-    'title' => 'Glossary Settings',
-    'page callback' => 'drupal_get_form',
-    'page arguments' => array('glossary_general_settings_form'),
-    'description' => 'Select how you want the Glossary module to behave.',
-    'access arguments' => array('administer filters'),
-    'type' => MENU_NORMAL_ITEM,
-    'file' => 'glossary.admin.inc',
-  );
-
-  $items['admin/config/content/glossary/general'] = array(
-    'title' => 'General',
-    'description' => 'General settings',
-    'page callback' => 'drupal_get_form',
-    'page arguments' => array('glossary_general_settings_form'),
-    'access arguments' => array('administer filters'),
-    'type' => MENU_DEFAULT_LOCAL_TASK,
-    'weight' => -3,
-    'file' => 'glossary.admin.inc',
-  );
-
-  $items['admin/config/content/glossary/alphabet'] = array(
-    'title' => 'Alphabet',
-    'access arguments' => array('administer filters'),
-    'page callback' => 'drupal_get_form',
-    'page arguments' => array('glossary_alphabet_form'),
-    'description' => 'Alphabet settings.',
-    'type' => MENU_LOCAL_TASK,
-    'weight' => 0,
-    'file' => 'glossary.admin.inc',
-  );
-
-  $items['admin/config/content/glossary/clearcache'] = array(
-    'title' => 'Clear cache',
-    'access arguments' => array('administer filters'),
-    'page callback' => 'drupal_get_form',
-    'page arguments' => array('glossary_clearcache_form'),
-    'description' => 'Clear the filter cache.',
-    'type' => MENU_LOCAL_TASK,
-    'weight' => 0,
-    'file' => 'glossary.admin.inc',
-  );
-
-  $result = db_query('SELECT format, name FROM {filter_format}');
-  foreach ($result as $filter) {
-    $format = $filter->format;
-    $enabled = db_query("SELECT COUNT(*) FROM {filter} WHERE format = :format AND module = :module", array(':format' => $format, ':module' => 'glossary'))->fetchField();
-    if ($enabled || !variable_get('glossary_hide_menus', FALSE)) {
-      $name = $filter->name;
-      $items['admin/config/content/glossary/filter/' . $format] = array(
-        'title' => '!name',
-        'title arguments' => array('!name' => $name),
-        'access arguments' => array('administer filters'),
-        'page callback' => 'drupal_get_form',
-        'page arguments' => array('glossary_filter_form', 5),
-        'description' => 'Settings for the !name input format.', array('!name' => $name),
-        'weight' => 2,
-        'type' => MENU_LOCAL_TASK,
-        'file' => 'glossary.admin.inc',
-      );
-    }
-  }
-
-  $items['glossary/term/%'] = array(
-    'title' => 'Glossary',
-    'page callback' => 'glossary_term',
-    'page arguments' => array(2),
-    'access arguments' => array('access glossary'),
-    'type' => MENU_CALLBACK,
-  );
-
-  return $items;
-}
-
-/**
- * Implements hook_permission().
- */
-function glossary_permission() {
-  return array(
-    'access glossary' => array(
-      'title' => t('access glossary'),
-      'description' => t("TODO Add a description for 'access glossary'"),
-    ),
-  );
-}
-
-/**
- * Implements hook_init().
- */
-function glossary_init() {
-  drupal_add_css(drupal_get_path('module', 'glossary') . '/glossary.css');
-}
-
-/**
- * @todo Please document this function.
- * @see http://drupal.org/node/1354
- */
-function glossary_search_form($form, $form_state, $keys = NULL) {
-  $form['#action'] = url('glossary/search');
-  $form['#attributes'] = array('class' => 'glossary search-form');
-  $form['keys'] = array(
-    '#type' => 'textfield',
-    '#title' => '',
-    '#default_value' => $keys,
-    '#size' => 15,
-  );
-  $form['search'] = array(
-    '#type' => 'submit',
-    '#value' => t('Search'),
-  );
-  return $form;
-}
-
-/**
- * @todo Please document this function.
- * @see http://drupal.org/node/1354
- */
-function glossary_search_form_submit($form, &$form_state) {
-  $keys = trim($form_state['values']['keys']);
-  $form_state['redirect'] = 'glossary/search/' . $keys;
-}
-
-/**
- * Present the search results.
- */
-function glossary_search_results($keys = NULL) {
-  $vids = _glossary_get_filter_vids();
-  $output = '<div class="glossary-list">';
-
-  $result = db_select('taxonomy_term_data', 't');
-  $result->addField('t', 'tid');
-  $result->condition('t.vid', $vids, 'IN')
-      ->condition(db_or()->condition('t.description', "%$keys%", 'LIKE')->condition('t.name', "%$keys%", 'LIKE'));
-  $result = $result->execute();
-
-  $found = NULL;
-  foreach ($result as $row) {
-    $term = taxonomy_term_load($row->tid);
-    $found .= '<dl>' . theme('glossary_overview_item', array(
-      'term' => $term,
-      'show_desc' => TRUE,
-      'dest' => NULL)
-    ) . '</dl>';
-  }
-
-  if (!$found) {
-    // @TODO: This returns a render array now.
-    $found = drupal_get_form('glossary_search_form', $keys) . '<p>' . t('Your search yielded no results') . glossary_help('glossary_search#noresults') . '</p>';
-    $found = drupal_render($found);
-  }
-
-  $output_title = t('Glossary search results');
-  $output .= '<div class="box"><h2 class="title">' . $output_title . '</h2><div class="content">' . $found . '</div></div>';
-  return $output . "</div>\n";
-}
-
-/**
- * @todo Please document this function.
- * @see http://drupal.org/node/1354
- */
-function theme_glossary_search_form($variables) {
-  $form = $variables['0'];
-  return '<div class="container-inline">' . drupal_render_children($form) . '</div>';
-}
-
-/**
- * Implements hook_theme().
- */
-function glossary_theme() {
-  return array(
-    'glossary_search_form' => array(
-      'variables' => array('form'),
-    ),
-    'glossary_overview_item' => array(
-      'variables' => array('term', 'show_desc', 'destination'),
-    ),
-    'glossary_block_term' => array(
-      'variables' => array('term', 'link'),
-    ),
-  );
-}
-
-/**
- * @todo Please document this function.
- * @see http://drupal.org/node/1354
- */
-function glossary_term($tid) {
-  $output = NULL;
-
-  $result = db_select('taxonomy_term_data', 't')
-      ->condition('tid', $tid)
-      ->addTag('term_access')
-      ->execute();
-  $output .= '<div class="glossary-list">' . "\n";
-  foreach ($result as $row) {
-    $term = taxonomy_term_load($row->tid);
-    drupal_set_title($term->name);
-    $output .= '<dl>' . theme('glossary_overview_item', array('term' => $term, 'show_desc' => TRUE)) . '</dl>';
-    $vid = $row->vid;
-  }
-  $output .= "</div>\n";
-
-  $tree = taxonomy_get_tree($vid);
-  $alphabar = _glossary_alphabar($vid, $tree);
-  $output = $alphabar . '<br/>' . $output;
-  return $output;
-}
-
-/**
- * Provide filter tip text.
- */
-function glossary_filter_glossary_tips($filter, $format, $long = FALSE) {
-  $block_tags = explode(' ', variable_get("glossary_blocking_tags_$format->format", 'abbr acronym'));
-  $standard_blocks = array('a');
-  foreach ($standard_blocks as $tag) {
-    if (!in_array($tag, $block_tags)) {
-      $block_tags[] = check_plain($tag);
-    }
-  }
-
-  foreach ($block_tags as $key => $tag) {
-    if ($tag[0] == '.') {
-      $block_tags[$key] = 'span class="' . check_plain(drupal_substr($tag, 1)) . '"';
-    }
-  }
-
-  sort($block_tags, SORT_STRING);
-  $blocked = implode(', ', $block_tags);
-  $more = ' ' . t('Additionally, these HTML elements will not be scanned: %blocked.', array('%blocked' => $blocked));
-
-  if ($long) {
-    return t('The Glossary module will automatically mark terms that have been defined in the glossary vocabulary with links to their descriptions. These marks depend on the settings and may be a superscript character or an icon, or the term may be turned into an acronym, cite, or abbreviation. If there are certain phrases or sections of text that should be excluded from glossary marking and linking, use the special markup, [no-glossary] ... [/no-glossary].') . $more;
-  }
-  else {
-    return t('Glossary terms will be automatically marked with links to their descriptions. If there are certain phrases or sections of text that should be excluded from glossary marking and linking, use the special markup, [no-glossary] ... [/no-glossary].') . $more;
-  }
-}
-
-/**
- * Implements hook_filter_info().
- */
-function glossary_filter_info() {
-  return array(
-    'glossary' => array(
-      'title' => t('Glossary filter'),
-      'description' => t('Maintain one or more glossaries on your site.'),
-      'process callback' => 'glossary_filter_glossary_process',
-      'tips callback' => 'glossary_filter_glossary_tips',
-    ),
-  );
-}
+use Drupal\Core\Routing\RouteMatchInterface;
 
 /**
- * Implements hook_taxonomy().
- */
-function glossary_taxonomy($op, $type, $array = NULL) {
-  if ($array) {
-    _glossary_clear_cache($array['vid']);
-  }
-}
-
-/**
- * Implements hook_user_XXX().
- */
-function glossary_user_XXX($edit, $account) {
-  // Note: this requires a setting. Do we also need to clear cache if selected?
-  if (variable_get('glossary_disable_indicator', FALSE)) {
-    $form['content_glossary'] = array(
-      '#type' => 'fieldset',
-      '#title' => t('Glossary Indicators'),
-    );
-    $form['content_glossary']['glossary_disable_indicator'] = array(
-      '#type' => 'checkbox',
-      '#title' => t('Disable Glossary indicators'),
-      '#return_value' => 1,
-      '#default_value' => $user->glossary_disable_indicator,
-      '#description' => t('Check this box to disable the display of Glossary indicators.'),
-    );
-    return $form;
-  }
-}
-
-/**
- * Implements hook_filter_FILTER_process().
- */
-function glossary_filter_glossary_process($text, $filter, $format, $langcode, $cache, $cache_id) {
-  global $user;
-  $format = $format->format;
-
-  if (isset($user->glossary_disable_indicator) && $user->glossary_disable_indicator && variable_get('glossary_disable_indicator', FALSE)) {
-    return $text;
-  }
-
-  if (isset($_REQUEST['q']) && strcmp($_REQUEST['q'], 'fckeditor/xss') == 0) {
-    return $text;
-  }
-
-  $current_term = 0;
-  if (strcmp(arg(0), 'taxonomy') == 0 && strcmp(arg(1), 'term') == 0 && arg(2) > 0) {
-    $current_term = arg(2);
-  }
-
-  if (variable_get("glossary_vids_$format", 0)) {
-    $text = ' ' . $text . ' ';
-    $replace_mode = variable_get("glossary_replace_$format", 'superscript');
-    $link_style = variable_get("glossary_link_$format", 'normal');
-    $absolute_link = ($link_style == 'absolute');
-    $terms = _glossary_get_terms($format);
-    $vids = _glossary_get_filter_vids();
-    $terms_replace = array();
-    $tip_list = array();
-
-    foreach ($terms as $term) {
-      if ($current_term == $term->tid) {
-        continue;
-      }
-
-      $term_title = $term->description;
-      $fragment = NULL;
-      if ($term->nodes > 0) {
-        $linkto = taxonomy_term_path($term);
-      }
-      elseif (!empty($vids) && (variable_get('glossary_click_option', 0) == 1)) {
-        if (variable_get('glossary_hide_if_empty', 1) && empty($term_title)) {
-          continue;
-        }
-        if (variable_get('glossary_page_per_letter', FALSE)) {
-          $linkto = 'glossary/' . $term->vid . '/letter' . drupal_strtolower(drupal_substr($term->name, 0, 1));
-        }
-        else {
-          $linkto = 'glossary/' . $term->vid;
-        }
-        $fragment = 'term' . $term->tid;
-      }
-      else {
-        $linkto = 'glossary/term/' . $term->tid;
-      }
-      $ins_before = $ins_after = NULL;
-      $term_class = variable_get('glossary_term_class', 'glossary-term');
-
-      switch ($replace_mode) {
-        case 'superscript':
-          $ins_after = '<sup class="glossary-indicator" title="' . $term_title . '">';
-          if ($link_style == 'none') {
-            $ins_after .= variable_get("glossary_superscript_$format", 'i');
-          }
-          else {
-            $ins_after .= l(variable_get("glossary_superscript_$format", 'i'), $linkto, array(
-              'attributes' => array('title' => $term_title, 'class' => 'glossary-indicator'),
-              'fragment' => $fragment,
-              'absolute' => $absolute_link,
-            ));
-          }
-          $ins_after .= '</sup>';
-          break;
-
-        case 'abbr':
-          if ($link_style == 'none') {
-            $ins_before .= '<span class="' . $term_class . '" title="' . $term_title . '"><' . $replace_mode . ' title="' . $term_title . '">';
-            $ins_after .= '</' . $replace_mode . '></span>';
-          }
-          else {
-            $ins_before .= '<' . $replace_mode . ' title="' . $term_title . '"><a class="' . $term_class . '" href="' . url($linkto, array('fragment' => $fragment, 'absolute' => $absolute_link)) . '" title="' . $term_title . '">';
-            $ins_after .= '</a></' . $replace_mode . '>';
-          }
-          break;
-
-        // TODO: remove first case after a while.
-        case 'acronym link':
-          $replace_mode = 'acronym';
-
-        case 'acronym':
-        case 'cite':
-        case 'dfn':
-          if ($link_style == 'none') {
-            $ins_after .= '</' . $replace_mode . '>';
-          }
-          else {
-            $ins_before .= '<a class="glossary-term" href="' . url($linkto, array('fragment' => $fragment, 'absolute' => $absolute_link)) . '">';
-            $ins_after .= '</' . $replace_mode . '></a>';
-          }
-          $ins_before .= '<' . $replace_mode . ' title="' . $term_title . '">';
-          break;
-
-        case 'clicktip':
-        case 'hovertip':
-          if ($link_style == 'none') {
-            $ins_after .= '</span>';
-          }
-          else {
-            $ins_before = '<a class="' . $term_class . '" href="' .
-                url($linkto, array('fragment' => $fragment, 'absolute' => $absolute_link)) . '">';
-            $ins_after .= '</span></a>';
-          }
-          $ins_before .= "<span $replace_mode=$term->tid>";
-          if (!isset($tip_list[$term->tid])) {
-            $tip_list[$term->tid] = '<span class="' . $replace_mode . '" id="' . $term->tid . '">' . $term->image . $term_title . '</span>';
-          }
-          $ins_after .= $tip_list[$term->tid];
-          break;
-
-        case 'iconterm':
-          // Icon format, plus term link.
-          $img = '<img src="' . base_path() . variable_get("glossary_icon_$format", 'glossary.gif') . "\" />";
-          if ($link_style == 'none') {
-            $ins_after .= $img;
-          }
-          else {
-            $ins_before .= '<a class="glossary-term" href="' . url($linkto, array('fragment' => $fragment, 'absolute' => $absolute_link)) . '">';
-            $ins_after = $img . '</a>';
-          }
-          break;
-
-        default:
-          // Icon format.
-          $img = '<img src="' . base_path() . variable_get("glossary_icon_$format", 'glossary.gif') . "\" />";
-          if ($link_style == 'none') {
-            $ins_after .= $img;
-          }
-          else {
-            $ins_after = l($img, $linkto, array(
-              'attributes' => array('title' => $term_title, 'class' => 'glossary-icon'),
-              'fragment' => $fragment,
-              'absolute' => $absolute_link,
-              'html' => TRUE,
-            ));
-          }
-          break;
-      }
-
-      // Replace term with the desired new HTML code.
-      $terms_replace[] = array(
-        'ins_before' => $ins_before,
-        'ins_after' => $ins_after,
-      );
-    }
-    return _glossary_insertlink($format, $text, $terms_replace);
-  }
-  $msg = 'returning <pre>' . $text . '</pre>';
-  drupal_set_message(check_plain($msg));
-  return $text;
-}
-
-/**
- * Insert glossary links to $text after every matching $terms[i]['synonyms'] that is not inside a blocking tag.
- * $terms[i]['ins_before'] is prepended to the matches, $terms[i]['ins_after'] is appended to them.
- * Match type and replace mode all depend on user settings.
- * The text is scanned once for all blocking tags and matches, then those 'events' are sorted and handled one by one.
- */
-function _glossary_insertlink($format, &$text, &$terms) {
-  $multibyte_enabled = extension_loaded('mbstring');
-  if ($multibyte_enabled) {
-    $mb_prefix = 'mb_';
-  }
-  else {
-    $mb_prefix = NULL;
-  }
-  $case_sensitive = variable_get("glossary_case_$format", '1');
-  $findfunc = $mb_prefix . 'strpos';
-  $findtagfunc = $mb_prefix . 'strpos';
-
-  $replaceall = variable_get("glossary_replace_all_$format", 0);
-
-  $events = array();
-
-  // Find blocking tags.
-  $open_tags = array('[no-glossary]', '<', '<a ', '[code');
-  $close_tags = array('[/no-glossary]', '>', '</a>', '[/code]');
-  // Use these always/when Codefilter module is on?.
-  // array('< ?php ', '[?php ', '<% ', '[% ', '[codefilter_');
-  // array('?'.'>', '?]', '%'.'>', '%]', '[/codefilter_');
-  $user_tags = explode(' ', variable_get("glossary_blocking_tags_$format", 'abbr acronym'));
-  foreach ($user_tags as $tag) {
-    if (!empty($tag)) {
-      if (ctype_alnum($tag)) {
-        $open_tags[] = "<$tag";
-        $close_tags[] = "</$tag>";
-      }
-      elseif ($tag[0] == '.') {
-        $open_tags[] = '<span class="' . drupal_substr($tag, 1);
-        $close_tags[] = "</span>";
-      }
-    }
-  }
-
-  $searchtext = $case_sensitive ? $text : drupal_strtolower($text);
-
-  foreach ($open_tags as $i => $tag) {
-    $offset = 0;
-    while (($offset = $findtagfunc($searchtext, $tag, $offset)) !== FALSE) {
-      // Longer tags will override shorter '<' on the same offset.
-      $events[$offset] = array(
-        'type' => 'open',
-        'which' => $i,
-      );
-      $offset += drupal_strlen($tag);
-    }
-  }
-
-  // Find match candidates.
-  // @TODO: We don't have synonyms any more.
-  foreach ($terms as $i => $term) {
-    foreach ($term['synonyms'] as $synonym) {
-      if (!$case_sensitive) {
-        $synonym = drupal_strtolower($synonym);
-      }
-      $offset = 0;
-      $first_match_found = FALSE;
-      while (($offset = $findfunc($searchtext, $synonym, $offset)) !== FALSE) {
-        $len = drupal_strlen($synonym);
-        $match = drupal_substr($text, $offset, $len);
-        // Only longer matches override shorter ones.
-        if (!isset($events[$offset]) || drupal_strlen($events[$offset]['match']) < drupal_strlen($match)) {
-          // Get synonym with case as in text.
-          $events[$offset] = array(
-            'type' => 'match',
-            'which' => $i,
-            'match' => $match,
-          );
-          if (!$replaceall) {
-            $first_match_found = TRUE;
-            break;
-          }
-        }
-        $offset += $len;
-      }
-      // TODO: remove this if we want different synonyms of the same term to
-      // be matched independently as 'first matches'.
-      if ($first_match_found && !$replaceall) {
-        break;
-      }
-    }
-  }
-
-  ksort($events);
-
-  $newtext = '';
-  // Text was parsed from chars 0 to $parsed (exclusive).
-  $parsed = 0;
-
-  foreach ($events as $place => $event) {
-    // Skip events inside blocking tag (they're already copied as is).
-    if ($place < $parsed) {
-      continue;
-    }
-    // Copy plain text (with no events).
-    $newtext .= drupal_substr($text, $parsed, ($place - $parsed));
-    $parsed = $place;
-    // If a blocking tag is opened, skip to closing tag.
-    if ($event['type'] == 'open') {
-      $skip = $findtagfunc($text, $close_tags[$event['which']], $place);
-      if ($skip === FALSE) {
-        $skip = drupal_strlen($text);
-      }
-      // If the tag is [no-glossary] - remove it with the closing tag
-      // (by incrementing $parsed without copying).
-      if ($event['which'] == 0) {
-        $parsed += drupal_strlen($open_tags[$event['which']]);
-        $newtext .= drupal_substr($text, $parsed, ($skip - $parsed));
-        $parsed = $skip + drupal_strlen($close_tags[$event['which']]);
-      }
-      // Copy text without changing it.
-      else {
-        $newtext .= drupal_substr($text, $parsed, ($skip - $parsed));
-        $parsed = $skip;
-      }
-    }
-    if ($event['type'] == 'match') {
-      $matchlen = drupal_strlen($event['match']);
-      $proper_match = FALSE;
-      switch (variable_get("glossary_match_$format", 'b')) {
-        // Require word break left or right.
-        case 'lr':
-          // $proper_match = (_glossary_is_boundary($text {$next - 1}) ||
-          // _glossary_is_boundary($text {$next + $matchlen}));
-          $proper_match = (_glossary_is_boundary(drupal_substr($text, $place - 1, 1)) ||
-              _glossary_is_boundary(drupal_substr($text, $place + $matchlen, 1)));
-          break;
-
-        // Require word break left and right.
-        case 'b':
-          // $proper_match = (_glossary_is_boundary($text {$next - 1})
-          // && _glossary_is_boundary($text {$next + $matchlen}));
-          $proper_match = (_glossary_is_boundary(drupal_substr($text, $place - 1, 1)) &&
-              _glossary_is_boundary(drupal_substr($text, $place + $matchlen, 1)));
-          break;
-
-        // Require word break left.
-        case 'l':
-          // $proper_match = _glossary_is_boundary($text {$next - 1});
-          $proper_match = _glossary_is_boundary(drupal_substr($text, $place - 1, 1));
-          break;
-
-        // Require word break right.
-        case 'r':
-          // $proper_match = _glossary_is_boundary($text {$next + $matchlen});
-          $proper_match = _glossary_is_boundary(drupal_substr($text, $place + $matchlen, 1));
-          break;
-
-        // Match any substring.
-        case 's':
-        default:
-          $proper_match = TRUE;
-          break;
-      }
-      if ($proper_match) {
-        $newtext .= $terms[$event['which']]['ins_before'] . $event['match'] . $terms[$event['which']]['ins_after'];
-        $parsed += $matchlen;
-      }
-    }
-  }
-
-  // Append remaining part.
-  return $newtext . drupal_substr($text, $parsed);
-}
-
-/**
- * Main glossary page function.
- */
-function glossary_page($vid = NULL, $letter = NULL) {
-  $vids = _glossary_get_filter_vids();
-  $found = FALSE;
-
-  if ($vid) {
-    $found = array_search($vid, $vids);
-  }
-  else {
-    if (count($vids) == 1) {
-      $vid = $vids[0];
-      $found = TRUE;
-    }
-  }
-
-  $breadcrumb = array(l(t('Home'), NULL));
-  if (!$vid || $found === FALSE) {
-    drupal_set_title(t('Glossaries'));
-    drupal_set_breadcrumb($breadcrumb);
-    return _glossary_list();
-  }
-  else {
-    $voc = taxonomy_vocabulary_load($vid);
-    if (count($vids) > 1) {
-      $breadcrumb[] = l(t('Glossaries'), 'glossary');
-    }
-    drupal_set_title(filter_xss_admin($voc->name));
-    drupal_set_breadcrumb($breadcrumb);
-    return glossary_overview($voc, $letter);
-  }
-}
-
-function _glossary_alphabar($vid, &$tree) {
-  $output = NULL;
-  $page_per_letter = variable_get('glossary_page_per_letter', FALSE);
-
-  if (variable_get('glossary_suppress_unused', FALSE)) {
-    // Just make it empty; it will be filled in below.
-    $letters = array();
-  }
-  else {
-    $lets = array_merge(variable_get('glossary_alphabet', range('a', 'z')), variable_get('glossary_digits', range('0', '9')));
-    $letters = drupal_map_assoc($lets);
-  }
-
-  foreach ($tree as $key => $term) {
-    $term->let = drupal_strtolower(drupal_substr($term->name, 0, 1));
-    if ($page_per_letter) {
-      $letters[$term->let] = l($term->let, 'glossary/' . $vid . '/letter' . $term->let, array('attributes' => array('class' => array('glossary-item'))));
-    }
-    else {
-      $letters[$term->let] = l($term->let, 'glossary/' . $vid, array('fragment' => 'letter' . $term->let, 'attributes' => array('class' => array('glossary-item'))));
-    }
-  }
-  $sep = ' ' . variable_get('glossary_alphabar_separator', '|') . ' ';
-  $output .= '<div class="glossary-links">' . implode($sep, $letters);
-
-  $output .= '<div class="glossary-alphabar-instructions">';
-  $output .= filter_xss(variable_get('glossary_alphabar_instruction', _alphabar_instruction_default()));
-  $output .= "</div></div>\n";
-
-  return $output;
-}
-
-/**
- * Produce the Glossary overview.
- */
-function glossary_overview($vocab, $letter = NULL) {
-  $dest = drupal_get_destination();
-  $output = '<div id="' . drupal_clean_css_identifier(drupal_strtolower($vocab->name)) . '">';
-
-  if ($vocab->description) {
-    $output .= '<p class="glossary-description">' . filter_xss_admin($vocab->description) . '</p>';
-  }
-
-  $vid = $vocab->vid;
-  if ($letter) {
-    $letter = drupal_substr($letter, 6, 1, 'UTF-8');
-    drupal_set_title(t('Glossary beginning with @let', array('@let' => drupal_strtoupper($letter))));
-  }
-  $current_let = '';
-
-  $no_overview = (variable_get('glossary_click_option', 0) == 0) && (variable_get('glossary_page_per_letter', FALSE) == TRUE);
-
-  $show_desc = variable_get('glossary_show_description', FALSE);
-  $separate = variable_get('glossary_separate_letters', FALSE);
-  $tree = taxonomy_get_tree($vid);
-
-  $output .= _glossary_alphabar($vid, $tree);
-
-  $output .= '<div class="glossary-list"><dl>' . "\n";
-
-  if ($tree) {
-    foreach ($tree as $term) {
-      // See if it's a new section.
-      // If we're looking for a single letter, see if this is it.
-      if ((!$no_overview && !$letter) || $term->let == $letter) {
-        // See if it's a new section.
-        if ($term->let != $current_let) {
-          $output .= "\n" . '<a id="letter' . $term->let . '"></a>';
-          if ($separate) {
-            $output .= '<div class="glossary-letter">' . $term->let . '</div>';
-          }
-          $current_let = $term->let;
-        }
-        $output .= theme('glossary_overview_item', array(
-          'term' => $term,
-          'show_desc' => $show_desc,
-          'dest' => $dest)
-        );
-      }
-    }
-    if ($current_let != '') {
-      $output .= '</dl>';
-    }
-  }
-  $output .= '</dl></div></div>';
-  return glossary_admin_links($vocab, $dest) . $output;
-}
-
-/**
- * Theme a glossary overview item.
- */
-function theme_glossary_overview_item($variables) {
-  $output = NULL;
-  $term = $variables['term'];
-  $show_desc = $variables['show_desc'];
-  $destination = $variables['dest'];
-  global $base_url;
-  static $click_option, $link_related, $show_detailed, $one_way, $tax_img_avail, $access_tax, $access_search, $show_edit, $show_search, $format;
-  if (!isset($click_option)) {
-    $click_option = variable_get('glossary_click_option', 0);
-    $link_related = variable_get('glossary_link_related', TRUE);
-    $show_detailed = variable_get('glossary_show_detailed', FALSE);
-    $show_edit = variable_get('glossary_show_edit', TRUE);
-    $show_search = variable_get('glossary_show_search', TRUE);
-    $one_way = variable_get('glossary_link_related_how', FALSE);
-    $tax_img_avail = module_exists('taxonomy_image');
-    $access_tax = user_access('administer taxonomy');
-    $access_search = user_access('search content');
-    $format = variable_get('glossary_default_filter', filter_default_format());
-  }
-
-  if ($tax_img_avail && $show_desc) {
-    $img = taxonomy_image_display($term->tid);
-    if ($img) {
-      $obj = taxonomy_image_get_object($term->tid);
-      $img = '<a href="' . $obj->url . '">' . $img . '</a>';
-    }
-  }
-  else {
-    $img = NULL;
-  }
-
-  if (!isset($term->depth)) {
-    $term->depth = 0;
-  }
-
-  $output .= '<dt class="depth' . $term->depth . '">' . $img;
-  $output .= '<a id="term' . $term->tid . '"></a>';
-
-  if ($show_desc) {
-    $output .= str_repeat("&mdash;", $term->depth) . filter_xss_admin($term->name);
-  }
-  else {
-    $output .= l($term->name, 'glossary/term/' . $term->tid) . ' ';
-  }
-
-  if ($show_edit && $access_tax) {
-    $output .= ' ' . l(t('edit term'), "taxonomy/term/$term->tid/edit", array(
-      'attributes' => array(
-        'class' => 'glossary-edit-term',
-        'title' => t('edit this term and definition'),
-      ),
-      'query' => $destination,
-      )
-    );
-  }
-
-  if ($show_search && $access_search) {
-    $output .= l(t('search for term'), 'search/node/"' . $term->name . '"', array('attributes' => array('class' => 'glossary-search-term', 'title' => t('search for content using this term')))
-    );
-  }
-  $output .= '</dt><dd class="depth' . $term->depth . '">';
-
-  if ($show_desc) {
-    if ($term->description) {
-      $output .= '<span class="glossary-term-description">'
-          . check_markup($term->description, $format)
-          . '</span>';
-    }
-    /*
-    if ($relations = glossary_get_related($term->tid, 'name', $one_way)) {
-    $output .= '<span class="glossary-related">' . t('See also') . ': ';
-    foreach ($relations as $related) {
-    $related->name = filter_xss($related->name);
-    if ($link_related) {
-    if ($click_option == 1) {
-    $items[] .= l($related->name, "glossary/$term->vid",
-    array('fragment' => "term$related->tid"));
-    }
-    else {
-    $items[] .= l($related->name, "glossary/term/$related->tid");
-    }
-    }
-    else {
-    $items[] .= check_plain($related->name);
-    }
-    }
-    $output .= implode(', ', $items) . "</span>\n";
-    unset($items);
-    }
-     */
-
-    // TODO Please convert this statement to the D7 database API syntax.
-    $detailed_exists = FALSE;
-    // $detailed_exists = db_query(db_rewrite_sql('SELECT COUNT(t.nid)
-    // FROM {taxonomy_term_node} t
-    // JOIN {node} n USING (nid)
-    // WHERE t.tid=%d AND n.status=1'), $term->tid)->fetchField();
-    if ($detailed_exists) {
-      // Do we want to show the teasers?
-      if ($show_detailed) {
-        $output .= '<div class="glossary-detailed">';
-        $text = NULL;
-        // TODO Please convert this statement to the D7 database API syntax.
-        /* There is not taxo_term_node any more. */
-        // $detailed = db_query(db_rewrite_sql('SELECT t.nid FROM
-        // {taxonomy_term_node} t JOIN {node} n USING (nid) WHERE t.tid=%d AND
-        // n.status=1'), $term->tid);
-        $detailed = db_query('taxonomy_index', 'ti')
-            ->innerJoin('node', 'n', 'n.nid = ti.nid');
-        $detailed->condition('t.tid', $term->tid)
-            ->condition('n.status', 1)
-            ->addTag('node_access')
-            ->addTag('term_access')
-            ->execute();
-        foreach ($detailed as $row) {
-          $node = node_load($row->nid);
-          // Format as teaser view with links.
-          $text .= node_view($node, TRUE, FALSE, TRUE);
-        }
-        if ($text) {
-          $fieldset = array(
-            '#title' => t('Detailed definition of @term', array('@term' => $term->name)),
-            '#collapsible' => TRUE,
-            '#collapsed' => TRUE,
-            '#value' => $text,
-          );
-          $output .= theme('fieldset', $fieldset);
-        }
-        $output .= "</div>\n";
-      }
-      else {
-        $output .= '<div class="glossary-detailed-link">' .
-            l(t('Detailed definition of @term', array('@term' => $term->name)), taxonomy_term_path($term))
-            . '</div>';
-      }
-    }
-  }
-  return $output;
-}
-
-/**
- * @todo Please document this function.
- * @see http://drupal.org/node/1354
- */
-function theme_glossary_block_term($variables) {
-  $term = $variables['0'];
-  $link = $variables['1'];
-  global $base_url;
-  static $click_option, $link_related, $one_way, $tax_img_avail;
-  if (!isset($click_option)) {
-    $click_option = variable_get('glossary_click_option', 0);
-    $link_related = variable_get('glossary_link_related', TRUE);
-    $one_way = variable_get('glossary_link_related_how', FALSE);
-    $tax_img_avail = module_exists('taxonomy_image');
-  }
-
-  if ($tax_img_avail) {
-    $img = taxonomy_image_display($term->tid);
-    if ($img) {
-      $obj = taxonomy_image_get_object($term->tid);
-      $img = '<a href="' . $obj->url . '">' . $img . '</a>';
-    }
-  }
-  else {
-    $img = NULL;
-  }
-
-  $output .= '<div class="glossary-block-term-name">';
-  $output .= $link ? l($term->name, 'glossary/term/' . $term->tid) : check_plain($term->name);
-  $output .= "</div>\n";
-
-  $output .= '<div class="glossary-block-term-description">';
-  $output .= $term->description ? check_markup($term->description) : NULL;
-  $output .= "</div>\n";
-
-  if ($relations = glossary_get_related($term->tid, 'name', $one_way)) {
-    $output .= '<span class="glossary-related">' . t('See also') . ': ';
-    $items = array();
-    foreach ($relations as $related) {
-      if ($link_related) {
-        if ($click_option == 1) {
-          $items[] .= l($related->name, 'glossary/' . $term->vid, array('fragment' => 'term' . $related->tid));
-        }
-        else {
-          $items[] .= l($related->name, 'glossary/term/' . $related->tid);
-        }
-      }
-      else {
-        $items[] .= check_plain($related->name);
-      }
-    }
-    $output .= implode(', ', $items) . "</span>\n";
-  }
-
-  return $output;
-}
-
-/**
- * Create Admin links for the overview.
- */
-function glossary_admin_links($vocabulary, $destination) {
-  $output = '<div class="glossary-admin-links">';
-  $links = array();
-  if (user_access('administer taxonomy')) {
-    $links['glossary_add_term'] = array(
-      'title' => t('Add term'),
-      'href' => 'admin/structure/taxonomy/' . $vocabulary->vid . '/add/term',
-    );
-    $n = drupal_strtolower($vocabulary->name);
-    $links['glossary_edit'] = array(
-      'title' => t('Edit @name', array('@name' => $n)),
-      // Is this secure?.
-      'href' => "admin/structure/taxonomy/$n/edit",
-      'query' => $destination,
-    );
-  }
-  if (user_access('administer filters')) {
-    $links['glossary_admin'] = array(
-      'title' => t('Glossary settings'),
-      'href' => 'admin/config/content/glossary',
-      'query' => $destination,
-    );
-  }
-
-  if (!empty($links)) {
-    $output .= theme('links', array('links' => $links, 'attributes' => array('class' => array('inline'))));
-  }
-  return $output . '</div>';
-}
-
-function _glossary_list() {
-  $output = "";
-  $destination = drupal_get_destination();
-  $vids = _glossary_get_filter_vids();
-  $vocs = array();
-  foreach ($vids as $vid) {
-    $voc = taxonomy_vocabulary_load($vid);
-    $vocs[$voc->name] = $voc;
-  }
-  uksort($vocs, '_glossary_cmp_strcase');
-
-  $eo = array('even', 'odd');
-  $i = 0;
-  $output .= '<table><tr><th>'
-      . t("Glossary name")
-      . '</th><th>'
-      . t('Operations')
-      . '</th></tr>';
-
-  foreach ($vocs as $voc) {
-    $links = array();
-    $class = $eo[++$i & 1];
-    if (user_access('administer taxonomy')) {
-      $links['glossary_edit'] = array(
-        'title' => t('Edit'),
-        'href' => 'admin/structure/taxonomy/edit/vocabulary/' . $voc->vid,
-        'query' => $destination,
-      );
-    }
-    $links['glossary_view'] = array(
-      'title' => t('List'),
-      'href' => 'glossary/' . $voc->vid,
-    );
-
-    if ($voc->description) {
-      $output .= '<tr class="' . $class . ' merge-down"><th>'
-          . filter_xss($voc->name)
-          // . check_plain($voc->name)
-          . '</th><td>'
-          . theme('links', array('links' => $links)) . '</td></tr>';
-      $output .= '<tr class="' . $class . ' merge-up"><td colspan="2" class="glossary-list-description">' . filter_xss($voc->description) . '</td></tr>';
-    }
-    else {
-      $output .= '<tr class="' . $class . '">';
-      $output .= '<th>'
-          . filter_xss($voc->name)
-          // . check_plain($voc->name)
-          . '</th><td>'
-          . theme('links', array('links' => $links))
-          . '</td></tr>';
-    }
-  }
-
-  // Were there any rows produced?.
-  if ($i == 0) {
-    $output .= '<tr><td colspan="5">' . t('No applicable vocabularies were found, please check your settings.') . '</td></tr>';
-  }
-  $output .= '</table>';
-
-  return $output;
-}
-
-function db_rewrite_sql($text) {
-  $where = debug_backtrace();
-  drupal_set_message(t('Function "@func" called on line @line of @file.', array(
-    '@func' => $where[0]['function'],
-    '@line' => $where[0]['line'],
-    '@file' => $where[0]['file'],
-      )), 'warning');
-  return $text;
-}
-
-/**
- * Get taxonomy terms.
- */
-function _glossary_get_terms($format) {
-  static $got = array();
-  $show_all = variable_get('glossary_allow_no_description', FALSE);
-  $taxonomy_image_enabled = module_exists('taxonomy_image');
-
-  if (!isset($got[$format])) {
-    $got[$format] = array();
-  }
-
-  if (!$terms = $got[$format]) {
-    $terms = array();
-    $vids = variable_get("glossary_vids_$format", 0);
-
-    foreach ($vids as $vid) {
-      // Get all glossary terms.
-      // Omit terms without a description. those are usually container terms.
-      // If multilingual taxonomy is enabled only show terms in current or no
-      // language.
-      $result = db_select('taxonomy_term_data', 'td');
-      // $result->leftJoin('taxonomy_index', 'ti');
-      $result->join('taxonomy_index', 'ti');
-
-      $result->fields('td', array('tid', 'name'))
-          ->addExpression('COUNT(ti.nid)', 'nodes');
-      $result->condition('td.vid', $vid)
-          ->groupBy('td.tid')
-          ->groupBy('td.name')
-          ->groupBy('td.description')
-          ->orderBy('LENGTH(td.name)', 'DESC');
-      if (module_exists('i18ntaxonomy')) {
-        global $language;
-        $result->condition('td.language', array('', $language->language), 'IN');
-      }
-
-      // $result->addTag('term_access');
-      $result->execute();
-      foreach ($result as $term) {
-        if ($term->nodes) {
-          // If there were any nodes attached, we need to
-          // see if they were unpublished.
-          // TODO Please convert this statement to the D7 database API syntax.
-          $unpubs = db_query(db_rewrite_sql("SELECT COUNT(n.nid) FROM {taxonomy_term_node} tn JOIN {node} n USING (nid) WHERE tn.tid=%d AND n.status=0"), $term->tid)->fetchField();
-          $term->nodes -= $unpubs;
-        }
-
-        if ($term->description || $show_all) {
-          $term->vid = $vid;
-          $terms[] = $term;
-        }
-        if ($taxonomy_image_enabled) {
-          $term->image = taxonomy_image_display($term->tid);
-        }
-        else {
-          $term->image = NULL;
-        }
-      }
-    }
-    $got[$format] = $terms;
-  }
-
-  return $terms;
-}
-
-/**
- * Find all term objects related to a given term ID Adapted frm taxonomy.module.
- *
- * @param int $tid
- *   the term id to look up.
- * @param bool $one_way
- *   whether to do one-way or two-way relations.
- * 
- * @return array
- *   an array related-tid => related-name
- */
-function glossary_get_related($tid, $key = 'tid', $one_way = FALSE) {
-  // D7 doesn't really support relationships.
-  return array();
-
-  if ($tid) {
-    $related = array();
-    $qargs = array_fill(0, 3, $tid);
-
-    if ($one_way) {
-      $result = db_query('SELECT r.tid2 FROM {taxonomy_term_relation} r WHERE r.tid1 = :r.tid1 ORDER BY r.tid2', array(':r.tid1' => $qargs));
-      foreach ($result as $term) {
-        // Hope that taxonomy has this cached to save a query.
-        $rel = taxonomy_term_load($term->tid2);
-        $related[$rel->$key] = $rel;
-      }
-    }
-    else {
-      // Two-way (normal taxonomy function).
-      // $result = db_query('SELECT t.*, tid1, tid2 FROM {taxonomy_term_relation
-      // }, {taxonomy_term_data} t WHERE (t.tid = :(t.tid OR t.tid = :t.tid AND
-      // (tid1 = :(tid1 OR tid2 = :tid2)AND t.tid != :t.tid ORDER BY weight,
-      // name', array(':(t.tid' => 'tid1', ':t.tid' => 'tid2', ':(tid1' =>
-      // $qargs)); 
-      // foreach ($result as $term) {
-      // $related[$term->$key] = $term;
-      // }
-    }
-
-    return $related;
-  }
-  else {
-    return array();
-  }
-}
-
-function _glossary_is_boundary($char) {
-  if (extension_loaded('mbstring')) {
-    return (mb_strpos("!\"#\$%&'()*+,-./:;<=>?@[\]^_`{|}~ï¿½ ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ \t\n\r", $char) !== FALSE);
-  }
-  else {
-    return (strpos("!\"#\$%&'()*+,-./:;<=>?@[\]^_`{|}~ï¿½ ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ \t\n\r", $char) !== FALSE);
-  }
-}
-
-/**
- * Menu call back for link on settings page.
- */
-function glossary_clearcache() {
-  cache_clear_all('*', 'cache_filter', TRUE);
-  drupal_set_message(t('Cache_filter cleared.'));
-  drupal_goto('/glossary');
-}
-
-function _glossary_clear_cache($format = NULL) {
-  // We could throw fewer things away if we checked which filter formats
-  // used the glossary filter, and we only threw those away. In practice,
-  // most if not all formats would use the glossary filter, so we just
-  // get rid of them all.
-  if (!is_array($format)) {
-    $wildcard = $format . ':';
-  }
-  if(empty($wildcard)) {
-    $wildcard = '*';
-  }
-  cache_clear_all($wildcard, 'cache_filter', TRUE);
-  drupal_set_message(t('The filter cache has been cleared. There may be a temporary performance degradation while it is rebuilt.'));
-}
-
-/**
- * Get an array of all vocabulary IDs associated with Glossary.
- *
- * @return array
- *   An array of vids.
- */
-function _glossary_get_filter_vids() {
-  // We can't use filter_formats() here, because we need all input formats,
-  // not just those we are allowed to post in.
-  $vids = array();
-  $result = db_query("SELECT format FROM {filter_format}");
-  foreach ($result as $format) {
-    $filters = filter_list_format($format->format);
-    foreach ($filters as $filter) {
-      if ($filter->module == "glossary") {
-        $vids = array_merge($vids, variable_get("glossary_vids_" . $format->format, array()));
-      }
-    }
-  }
-  return array_unique($vids);
-}
-
-function _glossary_cmp_strcase($a, $b) {
-  return strcmp(drupal_strtolower($a), drupal_strtolower($b));
-}
-
-function _alphabar_instruction_default() {
-  if (variable_get('glossary_page_per_letter', FALSE)) {
-    return t('Click one of the letters above to be taken to a page of all terms beginning with that letter.');
-  }
-  else {
-    return t('Click one of the letters above to advance the page to terms beginning with that letter.');
-  }
-}
-
-/**
- * Implements hook_block_info().
- */
-function glossary_block_info() {
-  // TODO Rename block deltas (e.g. glossary-search) to readable strings.
-  $blocks['glossary-search']['info'] = t('Glossary: Search');
-  $blocks['glossary-random']['info'] = t('Glossary: Random');
-  return $blocks;
-}
-
-/**
- * Implements hook_block_view().
- */
-function glossary_block_view($delta) {
-  // TODO Rename block deltas (e.g. glossary-search) to readable strings.
-  switch ($delta) {
-    case 'glossary-search':
-      $blocks['subject'] = t('Search Glossary');
-      $blocks['content'] = drupal_get_form('glossary_search_form');
-      return $blocks;
-
-    case 'glossary-random':
-      $interval = variable_get("glossary_block_{$delta}_interval", 0) * variable_get("glossary_block_{$delta}_step", 0);
-      $last = variable_get("glossary_block_{$delta}_last", 0);
-      if ($last + $interval < REQUEST_TIME) {
-        // Time to get a new selection.
-        $saved_vids = variable_get("glossary_block_{$delta}_vids", NULL);
-        if (is_null($saved_vids)) {
-          $blocks['content'] = t('Glossary block !blk has not been configured.', array('!blk' => $delta));
-          return $blocks;
-        }
-        $vids = array_filter($saved_vids);
-        if (count($vids) == 0) {
-          $vids = _glossary_get_filter_vids();
-        }
-        $placeholders = implode(',', array_fill(0, count($vids), '%d'));
-        // TODO Please convert this statement to the D7 database API syntax.
-        $tid = db_query_range('SELECT tid FROM {taxonomy_term_data} WHERE vid in (' . $placeholders . ') ORDER BY RAND()', $vids)->fetchField();
-        // Set now as the last selection and save that tid.
-        variable_set("glossary_block_{$delta}_last", REQUEST_TIME);
-        variable_set("glossary_block_{$delta}_tid", $tid);
-      }
-      else {
-        // Get the current selected tid.
-        $tid = variable_get("glossary_block_{$delta}_tid", 0);
-      }
-
-      $term = taxonomy_term_load($tid);
-      $blocks['content'] = theme('glossary_block_term', array(
-        '0' => $term,
-        '1' => variable_get("glossary_block_{$delta}_link", TRUE))
-      );
-      return $blocks;
-  }
-}
-
-/**
- * Implements hook_block_configure().
- */
-function glossary_block_configure($delta) {
-  // TODO Rename block deltas (e.g. glossary-search) to readable strings.
-  $form = array();
-  switch ($delta) {
-    case 'glossary-search':
-      // Search block - no config.
-      return $form;
-
-    case 'glossary-random':
-      $vids = array();
-      $vid_list = _glossary_get_filter_vids();
-      foreach ($vid_list as $vid) {
-        $voc = taxonomy_vocabulary_load($vid);
-        $vids[$vid] = check_plain($voc->name);
-      }
-      $form['vids'] = array(
-        '#type' => 'checkboxes',
-        '#title' => t('Choose from'),
-        '#description' => t('Select the vocabularies from which to choose a term.'),
-        '#options' => $vids,
-        '#default_value' => variable_get("glossary_block_{$delta}_vids", array()),
-        '#prefix' => '<div class="glossary_checkboxes">',
-        '#suffix' => '</div>',
-      );
-
-      $form['interval'] = array(
-        '#type' => 'textfield',
-        '#size' => 4,
-        '#maxlength' => 3,
-        '#default_value' => variable_get("glossary_block_{$delta}_interval", 0),
-        '#field_prefix' => '<strong>' . t('Update every') . '</strong>&nbsp;',
-        '#prefix' => '<div class="container-inline glossary-interval">',
-      );
-
-      $form['step'] = array(
-        '#type' => 'select',
-        '#default_value' => variable_get("glossary_block_{$delta}_step", 0),
-        '#options' => array(
-          1 => t('seconds'),
-          60 => t('minutes'),
-          3600 => t('hours'),
-          86400 => t('days'),
-        ),
-        '#suffix' => '</div>',
-        '#description' => t('How often do you want a new term? Leaving this blank or zero means every time.'),
-      );
-
-      $form['link'] = array(
-        '#type' => 'checkbox',
-        '#title' => t('Show term as link'),
-        '#default_value' => variable_get("glossary_block_{$delta}_link", TRUE),
-        '#description' => t('If selected, this option causes the term name to be made a link to the glossary entry.'),
-      );
-
-      return $form;
-  }
-  return $form;
-}
-
-/**
- * Implements hook_block_save().
+ * Implements hook_help().
  */
-function glossary_block_save($delta, $edit) {
-  // TODO Rename block deltas (e.g. glossary-search) to readable strings.
-  switch ($delta) {
-    case 'glossary-search':
-      // Search block - no config.
-      break;
+function glossary_help($route_name, RouteMatchInterface $route_match) {
+  switch ($route_name) {
+    // Main module help for the glossary module.
+    case 'help.page.glossary':
+      $output = '';
+      $output .= '<h3>' . t('About') . '</h3>';
+      $output .= '<p>' . t('Provides a filter that adds markup to terms from the Glossary vocabulary found in text. This markup allows for definition on hover.') . '</p>';
+      return $output;
 
-    case 'glossary-random':
-      variable_set("glossary_block_{$delta}_vids", $edit['vids']);
-      if (!$edit['interval'] || !is_numeric($edit['interval'])) {
-        // Make interval numeric;
-        $edit['interval'] = 0;
-      }
-      variable_set("glossary_block_{$delta}_interval", $edit['interval']);
-      variable_set("glossary_block_{$delta}_step", $edit['step']);
-      variable_set("glossary_block_{$delta}_link", $edit['link']);
-      break;
+    default:
   }
 }
diff --git a/readme.md b/readme.md
new file mode 100644
index 0000000..cbce58f
--- /dev/null
+++ b/readme.md
@@ -0,0 +1,7 @@
+Setup:
+*Create a vocabulary to hold the glossary terms.
+*Optionally add a boolean field, "field_glossary" as a per-node toggle.
+*Enable the glossary filter on at least one format at admin/config/content/formats
+*Configure it to use the glossary vocabulary.
+*Optionally configure it to use the toggle field.
+*Add CSS to visually show the glossary terms.
diff --git a/src/Plugin/Filter/Glossary.php b/src/Plugin/Filter/Glossary.php
new file mode 100644
index 0000000..04ee339
--- /dev/null
+++ b/src/Plugin/Filter/Glossary.php
@@ -0,0 +1,235 @@
+<?php
+
+namespace Drupal\glossary\Plugin\Filter;
+
+use Drupal\taxonomy\Entity\Term;
+use Drupal\filter\FilterProcessResult;
+use Drupal\filter\Plugin\FilterBase;
+use Drupal\Component\Utility\Unicode;
+use Drupal\Core\Form\FormStateInterface;
+
+/**
+ * Provides a filter provide a definition for glossary terms in text.
+ *
+ * @Filter(
+ *   id = "glossary",
+ *   title = @Translation("Glossary"),
+ *   description = @Translation("Glossary filter."),
+ *   type = Drupal\filter\Plugin\FilterInterface::TYPE_MARKUP_LANGUAGE,
+ * )
+ */
+class Glossary extends FilterBase {
+
+  /**
+   * {@inheritdoc}
+   */
+  public function settingsForm(array $form, FormStateInterface $form_state) {
+    $options = [];
+    $vocabularies = \Drupal\taxonomy\Entity\Vocabulary::loadMultiple();
+    foreach ($vocabularies as $key => $vocab) {
+      $options[$key] = $vocab->label();
+    }
+    $form['glossary_vocabulary'] = array(
+      '#type' => 'select',
+      '#title' => $this->t('Glossary vocabulary'),
+      '#description' => $this->t('Use this vocabulary as the vocabulary source.'),
+      '#default_value' => $this->settings['glossary_vocabulary'],
+      '#options' => $options,
+    );
+
+    $form['glossary_use_toggle_field'] = array(
+      '#type' => 'checkbox',
+      '#title' => $this->t('Use toggle field'),
+      '#description' => $this->t('When checked, the filter will look to see if field_glossary (on the node) is checked.'),
+      '#default_value' => $this->settings['glossary_use_toggle_field'],
+    );
+
+    return $form;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function setConfiguration(array $configuration) {
+    parent::setConfiguration($configuration);
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function process($text, $langcode) {
+    $use_toggle = $this->settings['glossary_use_toggle_field'];
+
+    $do_replace = TRUE;
+    if ($use_toggle) {
+      // If the setting is checked to allow toggling the glossary on and off
+      // per node, check the value on this node before doing the replacement.
+      $node = \Drupal::routeMatch()->getParameter('node');
+      $do_replace = $node && $node->hasField('field_glossary') && $node->field_glossary->value;
+    }
+
+    if ($do_replace) {
+      // Get all the terms in the vocabulary set as the glossary source.
+      $vocab = $this->settings['glossary_vocabulary'];
+      $terms = $this->getTerms($vocab);
+
+      // Make all the replacements.
+      $new_text = $this->doReplace($text, $terms);
+
+      // Create a filtered text object with the updated text.
+      $result = new FilterProcessResult($new_text);
+    }
+    else {
+      // Format the result out of the original text.
+      $result = new FilterProcessResult($text);
+    }
+
+    return $result;
+  }
+
+  /**
+   * Retrieve terms in a given vocabulary.
+   *
+   * @return array
+   *   All terms in the vocabulary in an array set up to be used in the
+   *   replacement function.
+   */
+  protected function getTerms($vocabulary) {
+    $query = \Drupal::entityQuery('taxonomy_term');
+    $query->condition('vid', $vocabulary);
+    $tids = $query->execute();
+    $terms = Term::loadMultiple($tids);
+
+    $termlist = [];
+    /** @var \Drupal\taxonomy\Entity\Term $term */
+    foreach ($terms as $term) {
+      // Create an array of the terms to send to the replace function.
+      $name = $term->getName();
+      $description = strip_tags($term->getDescription());
+      $termlist[] = [
+        'name' => $name,
+        'definition' => $description,
+        'replaced' => FALSE,
+      ];
+    }
+
+    return $termlist;
+  }
+
+  /**
+   * Replace terms in text with glossary markup.
+   *
+   * @param $text
+   *   Text that will have the terms replaced.
+   * @param array $terms
+   *   Term names and definitions.
+   *
+   * @return string
+   */
+  protected function doReplace(&$text, &$terms) {
+    // Change all the text to lowercase so we can search case insensitive.
+    $searchtext = Unicode::strtolower($text);
+
+    // These are the tags which will not be searched for the terms.
+    $open_tags = array('<a ', '<h1', '<h2', '<h3', '<h4', '<h5', '<h6');
+    $close_tags = array('</a>', '</h1>', '</h2>', '</h3>', '</h4>', '</h5>', '</h6>');
+
+    // Get a list of "events" which are both blocking tags and matches.
+    $events = array();
+    foreach ($open_tags as $key => $tag) {
+      $offset = 0;
+      while (($offset = Unicode::strpos($searchtext, $tag, $offset)) !== FALSE) {
+        // Longer tags will override shorter '<' on the same offset.
+        $events[$offset] = array(
+          'type' => 'open',
+          'which' => $key,
+        );
+        $offset += Unicode::strlen($tag);
+      }
+    }
+
+    // Find the match candidates.
+    foreach ($terms as $i => $term) {
+      $term_name = $term['name'];
+      $term_name = Unicode::strtolower($term_name);
+      $term_length = Unicode::strlen($term_name);
+
+      $offset = 0;
+      while (($offset = Unicode::strpos($searchtext, $term_name, $offset)) !== FALSE) {
+        $match = Unicode::substr($text, $offset, $term_length);
+
+        // Only longer matches override shorter ones.
+        if (!isset($events[$offset]) || Unicode::strlen($events[$offset]['match']) < Unicode::strlen($match)) {
+          $events[$offset] = array(
+            'type' => 'match',
+            'which' => $i,
+            'match' => $match,
+          );
+        }
+        $offset += $term_length;
+      }
+    }
+
+    ksort($events);
+
+    $newtext = '';
+    $parsed = 0;
+
+    // Do the replacements of the matched terms.
+    foreach ($events as $place => $event) {
+      // This event is in already parsed code so skip it. This skips match
+      // events that are within a blocked tag.
+      if ($place < $parsed) {
+        continue;
+      }
+
+      // Copy the text that came after the last event and prior to our current
+      // location in the text.
+      $newtext .= Unicode::substr($text, $parsed, ($place - $parsed));
+      $parsed = $place;
+
+      // If this event is the start of a blocked tag, skip over everything until
+      // the start of the closing tag. (The closing tag itself will be picked up
+      // with the "between event" text.)
+      if ($event['type'] == 'open') {
+        $skip = Unicode::strpos($text, $close_tags[$event['which']], $place);
+        if ($skip === FALSE) {
+          $skip = Unicode::strlen($text);
+        }
+
+        // Copy this skipped text as is.
+        $newtext .= Unicode::substr($text, $parsed, ($skip - $parsed));
+        $parsed = $skip;
+      }
+
+      if ($event['type'] == 'match') {
+        // Check to be sure the match is surrounded by word boundaries. That is,
+        // the word is not included inside another word.
+        $matched_length = Unicode::strlen($event['match']);
+        $term_id = $event['which'];
+        if ($this->isBoundary(Unicode::substr($text, $place - 1, 1)) && $this->isBoundary(Unicode::substr($text, $place + $matched_length, 1))) {
+          if (!$terms[$term_id]['replaced']) {
+            $newtext .= '<span class="glossary-term" data-term="' . $event['match'] . '" data-definition="' . $terms[$term_id]['definition'] . '" data-hasqtip="1">' . $event['match'] . '</span>';
+            $parsed += $matched_length;
+            $terms[$term_id]['replaced'] = TRUE;
+          }
+        }
+      }
+    }
+
+    // Append the remaining text.
+    return $newtext . Unicode::substr($text, $parsed);
+  }
+
+  /**
+   * Determine if the character is a boundary character.
+   *
+   * @param $char
+   *
+   * @return bool
+   */
+  protected function isBoundary($char) {
+    return Unicode::strpos("!\"#\$%&'()*+,-./:;<=>?@[\]^_`{|}~ï¿½ ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ \t\n\r", $char) !== FALSE;
+  }
+
+}
