 facetapi_bonus.metatag.inc | 91 ++++++++++++++++++++++++++++++++++++++++++++++
 facetapi_bonus.module      |  3 ++
 2 files changed, 94 insertions(+)

diff --git a/facetapi_bonus.metatag.inc b/facetapi_bonus.metatag.inc
new file mode 100644
index 0000000..cf26d18
--- /dev/null
+++ b/facetapi_bonus.metatag.inc
@@ -0,0 +1,91 @@
+<?php
+
+/**
+ * @file
+ * Implementations of metatag module API hooks.
+ *
+ * @see metatag.api.php
+ */
+
+/**
+ * Implements hook_metatag_token_types_alter().
+ */
+function facetapi_bonus_metatag_token_types_alter(&$options) {
+  if (isset($options['context']) && $options['context'] == 'views') {
+    $types = array(
+      'facetapi_results',
+      'facetapi_active',
+      'facetapi_facet',
+    );
+    if (!isset($options['token types'])) {
+      $options['token types'] = array();
+    }
+    $options['token types'] += $types;
+  }
+}
+
+ /**
+ * Implements hook_metatag_pattern_alter().
+ */
+function facetapi_bonus_metatag_pattern_alter(&$pattern, &$types) {
+  // Attempt to initialize tokens based on facetapi active searchers.
+  if ($searchers = facetapi_get_active_searchers()) {
+    // If we meet list<...[facetapi_active:XXX]...> string we replace it with
+    // coma separated list of tokenized string.
+    // So list<[facetapi_active:facet-label]: [facetapi_active:active-value]>
+    // will be replaced with "type: node, author: admin" string if type and
+    // author facets active.
+
+    $searcher = reset($searchers);
+    $adapter = facetapi_adapter_load($searcher);
+
+    // Provide explicit information for $data for the key facetapi_results
+    // replacements. This could be avoided if facetapi_tokens could provide
+    // default explicit values based on facetapi_get_active_searchers.
+    if (strpos($pattern, 'facetapi_results') !== FALSE) {
+      $types['facetapi_results'] = array('facetapi_adapter' => $adapter);
+    }
+
+    // Provide explicit information for $data for the key facetapi_active_item
+    // if any facetapi_active_item not wrapped in list<...> is found
+    if (preg_match_all('/[^list<]\[facetapi_active:[^>]/', $pattern, $matches)>0) {
+      // Select the item that was added last (so the most recently added filter).
+      if ($item = end($adapter->getAllActiveItems())) {
+        $item['adapter'] = $adapter;
+        $types['facetapi_active_item'] = $item;
+      }
+    }
+
+    // Provide explicit information for $data for the key facetapi_facet
+    if (strpos($pattern, 'facetapi_facet') !== FALSE) {
+      // Select the item that was added last (so the most recently added filter).
+      if ($item = end($adapter->getAllActiveItems())) {
+        $facet_name = $item['facets'][0];
+        $types['facetapi_facet'] = facetapi_facet_load($facet_name, $searcher);
+      }
+    }
+
+    // Handle the list iterator for the facetapi_active tokens.
+    // Currently facetapi_tokens doesn't support the iterator on this token.
+    if (strpos($pattern, 'list<') !== FALSE && strpos($pattern, 'facetapi_active') !== FALSE) {
+
+      preg_match_all('/list<[^>]*\[facetapi_active:[^>]*>/', $pattern, $matches);
+      $replacements = array();
+      foreach ($matches[0] as $subpattern) {
+        $string = substr($subpattern, 5, strlen($subpattern) - 6);
+        // @see CurrentSearchItemActive::execute().
+        $subreplacements = array();
+        foreach ($adapter->getAllActiveItems() as $item) {
+          // Adds adapter to the active item for token replacement.
+          $item['adapter'] = $adapter;
+          // Builds variables to pass to theme function.
+          $data = array('facetapi_active_item' => $item);
+
+          $subreplacements[] = token_replace($string, $data);
+        }
+        $replacements[$subpattern] = implode(', ', $subreplacements);
+      }
+      $pattern = str_replace(array_keys($replacements), array_values($replacements), $pattern);
+    }
+  }
+}
diff --git a/facetapi_bonus.module b/facetapi_bonus.module
index dd049db..54185eb 100644
--- a/facetapi_bonus.module
+++ b/facetapi_bonus.module
@@ -9,6 +9,9 @@
 // Integration with Page Title module.
 module_load_include('inc', 'facetapi_bonus', 'facetapi_bonus.page_title');
 
+// Integration with Meta tags module.
+module_load_include('inc', 'facetapi_bonus', 'facetapi_bonus.metatag');
+
 /**
  * Implements hook_facetapi_facet_info_alter().
  */
