commit 1e39edcbd90e902be8e4c9e4b54f668f2fbc02c7
Author: Assos Assos <assos+forge@centrale-marseille.fr>
Date:   Wed Nov 23 23:52:01 2016 +0100

    Weekly update of contrib modules

diff --git a/drupal7/sites/all/modules/ctools/bulk_export/bulk_export.info b/drupal7/sites/all/modules/ctools/bulk_export/bulk_export.info
index d9e4dfc8..22dc566a 100644
--- a/drupal7/sites/all/modules/ctools/bulk_export/bulk_export.info
+++ b/drupal7/sites/all/modules/ctools/bulk_export/bulk_export.info
@@ -6,9 +6,9 @@ package = Chaos tool suite
 version = CTOOLS_MODULE_VERSION
 
 
-; Information added by Drupal.org packaging script on 2016-10-16
-version = "7.x-1.11"
+; Information added by Drupal.org packaging script on 2016-11-22
+version = "7.x-1.12"
 core = "7.x"
 project = "ctools"
-datestamp = "1476581654"
+datestamp = "1479787162"
 
diff --git a/drupal7/sites/all/modules/ctools/css/button.css b/drupal7/sites/all/modules/ctools/css/button.css
index 15e484be..ead8f8ef 100644
--- a/drupal7/sites/all/modules/ctools/css/button.css
+++ b/drupal7/sites/all/modules/ctools/css/button.css
@@ -19,6 +19,7 @@
 .ctools-button-processed .ctools-content ul {
   list-style-image: none;
   list-style-type: none;
+  margin-left: 0;
 }
 
 .ctools-button-processed li {
diff --git a/drupal7/sites/all/modules/ctools/ctools.api.php b/drupal7/sites/all/modules/ctools/ctools.api.php
index a7ab7839..f328a7ca 100644
--- a/drupal7/sites/all/modules/ctools/ctools.api.php
+++ b/drupal7/sites/all/modules/ctools/ctools.api.php
@@ -199,7 +199,10 @@ function hook_ctools_render_alter(&$info, &$page, &$context) {
  * or categories or to rename content on specific sites.
  */
 function hook_ctools_content_subtype_alter($subtype, $plugin) {
-  $subtype['render last'] = TRUE;
+  // Force a particular subtype of a particular plugin to render last.
+  if ($plugin['module'] == 'some_plugin_module' && $plugin['name'] == 'some_plugin_name' && $subtype['subtype_id'] == 'my_subtype_id') {
+    $subtype['render last'] = TRUE;
+  }
 }
 
 /**
diff --git a/drupal7/sites/all/modules/ctools/ctools.info b/drupal7/sites/all/modules/ctools/ctools.info
index bdd3794c..3a2d031e 100644
--- a/drupal7/sites/all/modules/ctools/ctools.info
+++ b/drupal7/sites/all/modules/ctools/ctools.info
@@ -6,11 +6,19 @@ files[] = includes/context.inc
 files[] = includes/css-cache.inc
 files[] = includes/math-expr.inc
 files[] = includes/stylizer.inc
+
+; Tests.
+files[] = tests/context.test
+files[] = tests/css.test
 files[] = tests/css_cache.test
+files[] = tests/ctools.plugins.test
+files[] = tests/math_expression.test
+files[] = tests/math_expression_stack.test
+files[] = tests/object_cache.test
 
-; Information added by Drupal.org packaging script on 2016-10-16
-version = "7.x-1.11"
+; Information added by Drupal.org packaging script on 2016-11-22
+version = "7.x-1.12"
 core = "7.x"
 project = "ctools"
-datestamp = "1476581654"
+datestamp = "1479787162"
 
diff --git a/drupal7/sites/all/modules/ctools/ctools_access_ruleset/ctools_access_ruleset.info b/drupal7/sites/all/modules/ctools/ctools_access_ruleset/ctools_access_ruleset.info
index 8d5a77c4..bfa17834 100644
--- a/drupal7/sites/all/modules/ctools/ctools_access_ruleset/ctools_access_ruleset.info
+++ b/drupal7/sites/all/modules/ctools/ctools_access_ruleset/ctools_access_ruleset.info
@@ -5,9 +5,9 @@ package = Chaos tool suite
 version = CTOOLS_MODULE_VERSION
 dependencies[] = ctools
 
-; Information added by Drupal.org packaging script on 2016-10-16
-version = "7.x-1.11"
+; Information added by Drupal.org packaging script on 2016-11-22
+version = "7.x-1.12"
 core = "7.x"
 project = "ctools"
-datestamp = "1476581654"
+datestamp = "1479787162"
 
diff --git a/drupal7/sites/all/modules/ctools/ctools_ajax_sample/ctools_ajax_sample.info b/drupal7/sites/all/modules/ctools/ctools_ajax_sample/ctools_ajax_sample.info
index dcb634d7..52126d51 100644
--- a/drupal7/sites/all/modules/ctools/ctools_ajax_sample/ctools_ajax_sample.info
+++ b/drupal7/sites/all/modules/ctools/ctools_ajax_sample/ctools_ajax_sample.info
@@ -5,9 +5,9 @@ version = CTOOLS_MODULE_VERSION
 dependencies[] = ctools
 core = 7.x
 
-; Information added by Drupal.org packaging script on 2016-10-16
-version = "7.x-1.11"
+; Information added by Drupal.org packaging script on 2016-11-22
+version = "7.x-1.12"
 core = "7.x"
 project = "ctools"
-datestamp = "1476581654"
+datestamp = "1479787162"
 
diff --git a/drupal7/sites/all/modules/ctools/ctools_custom_content/ctools_custom_content.info b/drupal7/sites/all/modules/ctools/ctools_custom_content/ctools_custom_content.info
index 715e4539..ee2d2d1e 100644
--- a/drupal7/sites/all/modules/ctools/ctools_custom_content/ctools_custom_content.info
+++ b/drupal7/sites/all/modules/ctools/ctools_custom_content/ctools_custom_content.info
@@ -5,9 +5,9 @@ package = Chaos tool suite
 version = CTOOLS_MODULE_VERSION
 dependencies[] = ctools
 
-; Information added by Drupal.org packaging script on 2016-10-16
-version = "7.x-1.11"
+; Information added by Drupal.org packaging script on 2016-11-22
+version = "7.x-1.12"
 core = "7.x"
 project = "ctools"
-datestamp = "1476581654"
+datestamp = "1479787162"
 
diff --git a/drupal7/sites/all/modules/ctools/ctools_plugin_example/ctools_plugin_example.info b/drupal7/sites/all/modules/ctools/ctools_plugin_example/ctools_plugin_example.info
index 97b3ebfe..337e699d 100644
--- a/drupal7/sites/all/modules/ctools/ctools_plugin_example/ctools_plugin_example.info
+++ b/drupal7/sites/all/modules/ctools/ctools_plugin_example/ctools_plugin_example.info
@@ -8,9 +8,9 @@ dependencies[] = page_manager
 dependencies[] = advanced_help
 core = 7.x
 
-; Information added by Drupal.org packaging script on 2016-10-16
-version = "7.x-1.11"
+; Information added by Drupal.org packaging script on 2016-11-22
+version = "7.x-1.12"
 core = "7.x"
 project = "ctools"
-datestamp = "1476581654"
+datestamp = "1479787162"
 
diff --git a/drupal7/sites/all/modules/ctools/drush/ctools.drush.inc b/drupal7/sites/all/modules/ctools/drush/ctools.drush.inc
index 1862dbe9..0342c734 100644
--- a/drupal7/sites/all/modules/ctools/drush/ctools.drush.inc
+++ b/drupal7/sites/all/modules/ctools/drush/ctools.drush.inc
@@ -64,7 +64,7 @@ function ctools_drush_command() {
       'machine names' => 'Space separated list of exportables you want to view.',
     ),
     'options' => array(
-      'indent' => 'The string to use for indentation when dispalying the exportable export code. Defaults to \'\'.',
+      'indent' => 'The string to use for indentation when displaying the exportable export code. Defaults to \'\'.',
       'no-colour' => 'Remove any colour formatting from export string output. Ideal if you are sending the output of this command to a file.',
       'module' => $module_text,
       'all' => $all_text,
diff --git a/drupal7/sites/all/modules/ctools/includes/content.inc b/drupal7/sites/all/modules/ctools/includes/content.inc
index ae1c6073..6490d8d5 100644
--- a/drupal7/sites/all/modules/ctools/includes/content.inc
+++ b/drupal7/sites/all/modules/ctools/includes/content.inc
@@ -155,6 +155,11 @@ function ctools_content_get_subtypes($type) {
   // Walk through the subtypes and ensure minimal settings are
   // retained.
   foreach ($subtypes as $id => $subtype) {
+    // Ensure that the 'subtype_id' value exists.
+    if (!isset($subtype['subtype_id'])) {
+      $subtype['subtype_id'] = $id;
+    }
+
     // Use exact name since this is a modify by reference.
     ctools_content_prepare_subtype($subtypes[$id], $plugin);
   }
@@ -217,6 +222,7 @@ function ctools_content_prepare_subtype(&$subtype, $plugin) {
     }
   }
 
+  // Trigger hook_ctools_content_subtype_alter().
   drupal_alter('ctools_content_subtype', $subtype, $plugin);
 }
 
@@ -241,8 +247,8 @@ function ctools_content_prepare_subtype(&$subtype, $plugin) {
  *   Any incoming content, if this display is a wrapper.
  *
  * @return
- *   The content as rendered by the plugin. This content should be an array
- *   with the following possible keys:
+ *   The content as rendered by the plugin, or NULL.
+ *   This content should be an object with the following possible properties:
  *   - title: The safe to render title of the content.
  *   - title_heading: The title heading.
  *   - content: The safe to render HTML content.
diff --git a/drupal7/sites/all/modules/ctools/includes/context-access-admin.inc b/drupal7/sites/all/modules/ctools/includes/context-access-admin.inc
index 76643cf6..ea2a7c81 100644
--- a/drupal7/sites/all/modules/ctools/includes/context-access-admin.inc
+++ b/drupal7/sites/all/modules/ctools/includes/context-access-admin.inc
@@ -367,7 +367,6 @@ function ctools_access_ajax_edit($fragment = NULL, $id = NULL) {
     'contexts' => $contexts,
     'title' => t('Edit criteria'),
     'ajax' => TRUE,
-    'ajax' => TRUE,
     'modal' => TRUE,
     'modal return' => TRUE,
   );
diff --git a/drupal7/sites/all/modules/ctools/includes/context.inc b/drupal7/sites/all/modules/ctools/includes/context.inc
index 8b6d6032..a532f657 100644
--- a/drupal7/sites/all/modules/ctools/includes/context.inc
+++ b/drupal7/sites/all/modules/ctools/includes/context.inc
@@ -676,14 +676,19 @@ function ctools_context_keyword_substitute($string, $keywords, $contexts, $conve
         }
       }
 
-      if (empty($context_keywords[$context]) || !empty($context_keywords[$context]->empty)) {
-        $keywords['%' . $keyword] = '';
-      }
-      else if (!empty($converter)) {
-        $keywords['%' . $keyword] = ctools_context_convert_context($context_keywords[$context], $converter, $converter_options);
+      if (!isset($context_keywords[$context])) {
+        $keywords['%' . $keyword] = '%' . $keyword;
       }
       else {
-        $keywords['%' . $keyword] = $context_keywords[$keyword]->title;
+        if (empty($context_keywords[$context]) || !empty($context_keywords[$context]->empty)) {
+          $keywords['%' . $keyword] = '';
+        }
+        else if (!empty($converter)) {
+          $keywords['%' . $keyword] = ctools_context_convert_context($context_keywords[$context], $converter, $converter_options);
+        }
+        else {
+          $keywords['%' . $keyword] = $context_keywords[$keyword]->title;
+        }
       }
     }
   }
diff --git a/drupal7/sites/all/modules/ctools/includes/plugins.inc b/drupal7/sites/all/modules/ctools/includes/plugins.inc
index 65f36629..d524f746 100644
--- a/drupal7/sites/all/modules/ctools/includes/plugins.inc
+++ b/drupal7/sites/all/modules/ctools/includes/plugins.inc
@@ -200,18 +200,18 @@ function ctools_plugin_api_get_hook($owner, $api) {
 /**
  * Fetch a group of plugins by name.
  *
- * @param $module
- *   The name of the module that utilizes this plugin system. It will be
- *   used to call hook_ctools_plugin_$plugin() to get more data about the plugin.
- * @param $type
+ * @param string $module
+ *   The name of the module that utilizes this plugin system. It will be used to
+ *   get more data about the plugin as defined on hook_ctools_plugin_type().
+ * @param string $type
  *   The type identifier of the plugin.
- * @param $id
+ * @param string $id
  *   If specified, return only information about plugin with this identifier.
  *   The system will do its utmost to load only plugins with this id.
  *
- * @return
- *   An array of information arrays about the plugins received. The contents
- *   of the array are specific to the plugin.
+ * @return array
+ *   An array of information arrays about the plugins received. The contents of
+ *   the array are specific to the plugin.
  */
 function ctools_get_plugins($module, $type, $id = NULL) {
   // Store local caches of plugins and plugin info so we don't have to do full
@@ -224,10 +224,14 @@ function ctools_get_plugins($module, $type, $id = NULL) {
 
   $info = ctools_plugin_get_plugin_type_info();
 
-  // Bail out noisily if an invalid module/type combination is requested.
   if (!isset($info[$module][$type])) {
-    watchdog('ctools', 'Invalid plugin module/type combination requested: module @module and type @type', array('@module' => $module, '@type' => $type), WATCHDOG_ERROR);
-    return array();
+    // If we don't find the plugin we attempt a cache rebuild before bailing out
+    $info = ctools_plugin_get_plugin_type_info(TRUE);
+    // Bail out noisily if an invalid module/type combination is requested.
+    if (!isset($info[$module][$type])) {
+      watchdog('ctools', 'Invalid plugin module/type combination requested: module @module and type @type', array('@module' => $module, '@type' => $type), WATCHDOG_ERROR);
+      return array();
+    }
   }
 
   // Make sure our plugins array is populated.
@@ -235,8 +239,8 @@ function ctools_get_plugins($module, $type, $id = NULL) {
     $plugins[$module][$type] = array();
   }
 
-  // Attempt to shortcut this whole piece of code if we already have
-  // the requested plugin:
+  // Attempt to shortcut this whole piece of code if we already have the
+  // requested plugin:
   if ($id && array_key_exists($id, $plugins[$module][$type])) {
     return $plugins[$module][$type][$id];
   }
@@ -271,8 +275,8 @@ function ctools_get_plugins($module, $type, $id = NULL) {
     $plugins[$module][$type] = ctools_plugin_load_hooks($info[$module][$type]);
   }
 
-  // Then see if we should load all files. We only do this if we
-  // want a list of all plugins or there was a cache miss.
+  // Then see if we should load all files. We only do this if we want a list of
+  // all plugins or there was a cache miss.
   if (empty($setup[$module][$type]) && ($build_cache || !$id)) {
     $setup[$module][$type] = TRUE;
     $plugins[$module][$type] = array_merge($plugins[$module][$type], ctools_plugin_load_includes($info[$module][$type]));
@@ -296,8 +300,8 @@ function ctools_get_plugins($module, $type, $id = NULL) {
   }
 
 
-  // If we were told earlier that this is cacheable and the cache was
-  // empty, give something back.
+  // If we were told earlier that this is cacheable and the cache was empty,
+  // give something back.
   if ($build_cache) {
     cache_set("plugins:$module:$type", $plugins[$module][$type], $info[$module][$type]['cache table']);
   }
diff --git a/drupal7/sites/all/modules/ctools/includes/uuid.inc b/drupal7/sites/all/modules/ctools/includes/uuid.inc
index 6e4c42c3..13897f1f 100644
--- a/drupal7/sites/all/modules/ctools/includes/uuid.inc
+++ b/drupal7/sites/all/modules/ctools/includes/uuid.inc
@@ -9,7 +9,9 @@
 /**
  * Pattern for detecting a valid UUID.
  */
-define('UUID_PATTERN', '[0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12}');
+if (!defined('UUID_PATTERN')) {
+  define('UUID_PATTERN', '[0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12}');
+}
 
 /**
  * Generates a UUID using the Windows internal GUID generator.
diff --git a/drupal7/sites/all/modules/ctools/page_manager/help/getting-started.html b/drupal7/sites/all/modules/ctools/page_manager/help/getting-started.html
index 4e4f24ae..6a75a370 100644
--- a/drupal7/sites/all/modules/ctools/page_manager/help/getting-started.html
+++ b/drupal7/sites/all/modules/ctools/page_manager/help/getting-started.html
@@ -4,7 +4,7 @@ Note: this page is currently very preliminary. Please visit <a href="http://drup
 This is a quick summary:
 
 <ul>
-<li>Visit administer >> site building >> pages to get to the primary page manager interface.</li>
+<li>Visit administer >> structure >> pages to get to the primary page manager interface.</li>
 <li>You can add custom pages for your basic landing pages, front pages, whatever you like for normal content display.</li>
 <li>You can use the system pages to create finer control of how taxonomy vocabularies, nodes and user profiles are displayed.</li>
 <li>When you add your first custom page, do not bother with the optional features. You will not need these until you get to more advanced tasks.</li>
diff --git a/drupal7/sites/all/modules/ctools/page_manager/page_manager.admin.inc b/drupal7/sites/all/modules/ctools/page_manager/page_manager.admin.inc
index 2a78fd9f..95d12255 100644
--- a/drupal7/sites/all/modules/ctools/page_manager/page_manager.admin.inc
+++ b/drupal7/sites/all/modules/ctools/page_manager/page_manager.admin.inc
@@ -1688,6 +1688,12 @@ function page_manager_handler_clone_submit(&$form, &$form_state) {
 
   page_manager_handler_add_to_page($form_state['page'], $handler, $form_state['values']['title']);
 
+  // Variant is cloned and added to the Page. Ensure the uuids are re-generated.
+  panels_panel_context_get_display($handler);
+  if (isset($handler->conf['display']) && method_exists($handler->conf['display'], 'clone_display')) {
+    $handler->conf['display'] = $handler->conf['display']->clone_display();
+  }
+
   $plugin = page_manager_get_task_handler($handler->handler);
   // It has no forms at all. Add the variant and go to its first operation.
   $keys = array_keys($plugin['operations']);
diff --git a/drupal7/sites/all/modules/ctools/page_manager/page_manager.info b/drupal7/sites/all/modules/ctools/page_manager/page_manager.info
index 944c7976..9fe2b2f4 100644
--- a/drupal7/sites/all/modules/ctools/page_manager/page_manager.info
+++ b/drupal7/sites/all/modules/ctools/page_manager/page_manager.info
@@ -5,9 +5,9 @@ dependencies[] = ctools
 package = Chaos tool suite
 version = CTOOLS_MODULE_VERSION
 
-; Information added by Drupal.org packaging script on 2016-10-16
-version = "7.x-1.11"
+; Information added by Drupal.org packaging script on 2016-11-22
+version = "7.x-1.12"
 core = "7.x"
 project = "ctools"
-datestamp = "1476581654"
+datestamp = "1479787162"
 
diff --git a/drupal7/sites/all/modules/ctools/page_manager/plugins/tasks/page.admin.inc b/drupal7/sites/all/modules/ctools/page_manager/plugins/tasks/page.admin.inc
index 5cc12834..b2ae8cbe 100644
--- a/drupal7/sites/all/modules/ctools/page_manager/plugins/tasks/page.admin.inc
+++ b/drupal7/sites/all/modules/ctools/page_manager/plugins/tasks/page.admin.inc
@@ -1462,6 +1462,15 @@ function page_manager_page_form_clone_submit(&$form, &$form_state) {
   $original->path = $form_state['values']['path'];
 
   $handlers = !empty($form_state['values']['handlers']) ? $form_state['page']->handlers : FALSE;
+  // Ensure the handler uuids are re-generated.
+  if ($handlers) {
+    foreach ($handlers as &$handler) {
+      if (isset($handler->conf['display']) && method_exists($handler->conf['display'], 'clone_display')) {
+        $handler->conf['display'] = $handler->conf['display']->clone_display();
+      }
+    }
+  }
+
   // Export the handler, which is a fantastic way to clean database IDs out of it.
   $export = page_manager_page_export($original, $handlers);
   ob_start();
diff --git a/drupal7/sites/all/modules/ctools/plugins/arguments/terms.inc b/drupal7/sites/all/modules/ctools/plugins/arguments/terms.inc
index 4298ea91..d31f28de 100644
--- a/drupal7/sites/all/modules/ctools/plugins/arguments/terms.inc
+++ b/drupal7/sites/all/modules/ctools/plugins/arguments/terms.inc
@@ -65,6 +65,7 @@ function ctools_terms_breadcrumb($conf, $context) {
     return;
   }
 
+  $current = new stdClass();
   $current->tid = $context->tids[0];
   $breadcrumb = array();
   while ($parents = taxonomy_get_parents($current->tid)) {
diff --git a/drupal7/sites/all/modules/ctools/plugins/content_types/block/block.inc b/drupal7/sites/all/modules/ctools/plugins/content_types/block/block.inc
index 4d4c31c3..46b02e9e 100644
--- a/drupal7/sites/all/modules/ctools/plugins/content_types/block/block.inc
+++ b/drupal7/sites/all/modules/ctools/plugins/content_types/block/block.inc
@@ -372,9 +372,9 @@ function profile_ctools_block_info($module, $delta, &$info) {
 }
 
 function book_ctools_block_info($module, $delta, &$info) {
-  // Hide the book navigation block which isn't as rich as what we can
-  // do with context.
-  $info = NULL;
+  $info['title'] = t('Book navigation menu');
+  $info['icon'] = 'icon_core_block_menu.png';
+  $info['category'] = t('Node');
 }
 
 function blog_ctools_block_info($module, $delta, &$info) {
diff --git a/drupal7/sites/all/modules/ctools/plugins/content_types/node_context/node_book_menu.inc b/drupal7/sites/all/modules/ctools/plugins/content_types/node_context/node_book_menu.inc
new file mode 100644
index 00000000..84497c85
--- /dev/null
+++ b/drupal7/sites/all/modules/ctools/plugins/content_types/node_context/node_book_menu.inc
@@ -0,0 +1,101 @@
+<?php
+
+if (module_exists('book')) {
+  /**
+   * Plugins are described by creating a $plugin array which will be used
+   * by the system that includes this file.
+   */
+  $plugin = array(
+    'single' => TRUE,
+    'title' => t('Book navigation menu'),
+    'icon' => '../block/icon_core_block_menu.png',
+    'description' => t('The book menu belonging to the current book node.'),
+    'required context' => new ctools_context_required(t('Node'), 'node'),
+    'category' => t('Node'),
+  );
+}
+
+function ctools_node_book_menu_content_type_render($subtype, $conf, $panel_args, $context) {
+  $node = isset($context->data) ? clone($context->data) : NULL;
+  $block = new stdClass();
+  $block->module = 'book_menu';
+
+  if ($conf['override_title']) {
+    $block->title = t($conf['override_title_text']);
+  }
+  else {
+    $block->title = t('Book navigation menu');
+  }
+  if ($node) {
+    $block->delta = $node->nid;
+    // TODO: the value is not available somehow?!?
+    $book_block_mode = isset($conf['book_block_mode']) ? $conf['book_block_mode'] : 'book pages';
+
+    // Code below is taken from function book_block_view().
+    $current_bid = empty($node->book['bid']) ? 0 : $node->book['bid'];
+
+    if ($book_block_mode === 'all pages') {
+      $block->subject = t('Book navigation');
+      $book_menus = array();
+      $pseudo_tree = array(0 => array('below' => FALSE));
+      foreach (book_get_books() as $book_id => $book) {
+        if ($book['bid'] === $current_bid) {
+          // If the current page is a node associated with a book, the menu
+          // needs to be retrieved.
+          $book_menus[$book_id] = menu_tree_output(menu_tree_all_data($node->book['menu_name'], $node->book));
+        }
+        else {
+          // Since we know we will only display a link to the top node, there
+          // is no reason to run an additional menu tree query for each book.
+          $book['in_active_trail'] = FALSE;
+          // Check whether user can access the book link.
+          $book_node = node_load($book['nid']);
+          $book['access'] = node_access('view', $book_node);
+          $pseudo_tree[0]['link'] = $book;
+          $book_menus[$book_id] = menu_tree_output($pseudo_tree);
+        }
+      }
+      $book_menus['#theme'] = 'book_all_books_block';
+      $block->content = $book_menus;
+    }
+    elseif ($current_bid) {
+      // Only display this block when the user is browsing a book.
+      $select = db_select('node', 'n')
+          ->fields('n', array('title'))
+          ->condition('n.nid', $node->book['bid'])
+          ->addTag('node_access');
+      $title = $select->execute()->fetchField();
+      // Only show the block if the user has view access for the top-level node.
+      if ($title) {
+        $tree = menu_tree_all_data($node->book['menu_name'], $node->book);
+        // There should only be one element at the top level.
+        $data = array_shift($tree);
+        // TODO: subject is not rendered
+        $block->subject = theme('book_title_link', array('link' => $data['link']));
+        $block->content = ($data['below']) ? menu_tree_output($data['below']) : '';
+      }
+    }
+  }
+  else {
+    $block->content = t('Book navigation pager goes here.');
+    $block->delta = 'unknown';
+  }
+
+  return $block;
+}
+
+function ctools_node_book_menu_content_type_admin_title($subtype, $conf, $context) {
+  return t('"@s" book navigation pager', array('@s' => $context->identifier));
+}
+
+function ctools_node_book_menu_content_type_edit_form($form, &$form_state) {
+  // Grab block form from the book module.
+  $block_form = book_block_configure($delta = '');
+  // TODO: this does not work yet.
+  //       See TODO in: ctools_node_book_menu_content_type_render
+  if (isset($form_state['input']['book_block_mode'])) {
+    $block_form['book_block_mode']['#default_value'] = $form_state['input']['book_block_mode'];
+  }
+  $form += $block_form;
+  return $form;
+}
diff --git a/drupal7/sites/all/modules/ctools/plugins/content_types/node_context/node_book_nav.inc b/drupal7/sites/all/modules/ctools/plugins/content_types/node_context/node_book_nav.inc
index 403db8d1..f0529b43 100644
--- a/drupal7/sites/all/modules/ctools/plugins/content_types/node_context/node_book_nav.inc
+++ b/drupal7/sites/all/modules/ctools/plugins/content_types/node_context/node_book_nav.inc
@@ -7,9 +7,9 @@ if (module_exists('book')) {
    */
   $plugin = array(
     'single' => TRUE,
-    'title' => t('Book navigation'),
-    'icon' => 'icon_node.png',
-    'description' => t('The navigation menu the book the node belongs to.'),
+    'title' => t('Book navigation pager'),
+    'icon' => '../block/icon_core_booknavigation.png',
+    'description' => t('The navigational pager and sub pages of the current book node.'),
     'required context' => new ctools_context_required(t('Node'), 'node'),
     'category' => t('Node'),
   );
@@ -20,13 +20,13 @@ function ctools_node_book_nav_content_type_render($subtype, $conf, $panel_args,
   $block = new stdClass();
   $block->module = 'book_nav';
 
-  $block->title = t('Book navigation');
+  $block->title = t('Book navigation pager');
   if ($node) {
     $block->content = isset($node->book) ? theme('book_navigation', array('book_link' => $node->book)) : '';
     $block->delta = $node->nid;
   }
   else {
-    $block->content = t('Book navigation goes here.');
+    $block->content = t('Book navigation pager goes here.');
     $block->delta = 'unknown';
   }
 
@@ -34,7 +34,7 @@ function ctools_node_book_nav_content_type_render($subtype, $conf, $panel_args,
 }
 
 function ctools_node_book_nav_content_type_admin_title($subtype, $conf, $context) {
-  return t('"@s" book navigation', array('@s' => $context->identifier));
+  return t('"@s" book navigation pager', array('@s' => $context->identifier));
 }
 
 function ctools_node_book_nav_content_type_edit_form($form, &$form_state) {
diff --git a/drupal7/sites/all/modules/ctools/stylizer/stylizer.info b/drupal7/sites/all/modules/ctools/stylizer/stylizer.info
index 66957648..79dc8929 100644
--- a/drupal7/sites/all/modules/ctools/stylizer/stylizer.info
+++ b/drupal7/sites/all/modules/ctools/stylizer/stylizer.info
@@ -6,9 +6,9 @@ version = CTOOLS_MODULE_VERSION
 dependencies[] = ctools
 dependencies[] = color
 
-; Information added by Drupal.org packaging script on 2016-10-16
-version = "7.x-1.11"
+; Information added by Drupal.org packaging script on 2016-11-22
+version = "7.x-1.12"
 core = "7.x"
 project = "ctools"
-datestamp = "1476581654"
+datestamp = "1479787162"
 
diff --git a/drupal7/sites/all/modules/ctools/term_depth/term_depth.info b/drupal7/sites/all/modules/ctools/term_depth/term_depth.info
index 91701667..885a5d0d 100644
--- a/drupal7/sites/all/modules/ctools/term_depth/term_depth.info
+++ b/drupal7/sites/all/modules/ctools/term_depth/term_depth.info
@@ -5,9 +5,9 @@ dependencies[] = ctools
 package = Chaos tool suite
 version = CTOOLS_MODULE_VERSION
 
-; Information added by Drupal.org packaging script on 2016-10-16
-version = "7.x-1.11"
+; Information added by Drupal.org packaging script on 2016-11-22
+version = "7.x-1.12"
 core = "7.x"
 project = "ctools"
-datestamp = "1476581654"
+datestamp = "1479787162"
 
diff --git a/drupal7/sites/all/modules/ctools/tests/context.test b/drupal7/sites/all/modules/ctools/tests/context.test
index bdf14e3f..2dd4f4d4 100644
--- a/drupal7/sites/all/modules/ctools/tests/context.test
+++ b/drupal7/sites/all/modules/ctools/tests/context.test
@@ -5,7 +5,7 @@ class CtoolsContextKeywordsSubstitutionTestCase extends DrupalWebTestCase {
     return array(
       'name' => 'Keywords substitution',
       'description' => 'Verify that keywords are properly replaced with data.',
-      'group' => 'Chaos Tools Suite',
+      'group' => 'ctools',
     );
   }
 
@@ -51,6 +51,30 @@ class CtoolsContextKeywordsSubstitutionTestCase extends DrupalWebTestCase {
         "%{$node->title}",
         t('Keyword after escaped and unescaped percent sign has been replaced.'),
       ),
+      '%%foo:bar' => array(
+        "%foo:bar",
+        t('Non-existant context ignored.'),
+      ),
+      'There was about 20%-30% difference in price.' => array(
+        'There was about 20%-30% difference in price.',
+        t('Non-keyword percent sign left untouched.'),
+      ),
+      'href="my%20file%2dname.pdf"' => array(
+        'href="my%20file%2dname.pdf"',
+        t('HTTP URL escape left untouched.'),
+      ),
+      'href="my%a0file%fdname.pdf"' => array(
+        'href="my%a0file%fdname.pdf"',
+        t('HTTP URL escape (high-chars) left untouched.'),
+      ),
+      '<a href="http://www.example.com/here%20is%20a%20pdf.pdf">Click here!</a>' => array(
+        '<a href="http://www.example.com/here%20is%20a%20pdf.pdf">Click here!</a>',
+        t('HTTP URL escape percent sign left untouched in HTML.'),
+      ),
+      'SELECT * FROM {table} WHERE field = "%s"' => array(
+        'SELECT * FROM {table} WHERE field = "%s"',
+        t('SQL percent sign left untouched.'),
+      ),
     );
     foreach ($checks as $string => $expectations) {
       list($expected_result, $message) = $expectations;
diff --git a/drupal7/sites/all/modules/ctools/tests/css.test b/drupal7/sites/all/modules/ctools/tests/css.test
index 4a5200ca..3ffd42a5 100644
--- a/drupal7/sites/all/modules/ctools/tests/css.test
+++ b/drupal7/sites/all/modules/ctools/tests/css.test
@@ -12,7 +12,7 @@ class CtoolsCssTestCase extends DrupalWebTestCase {
     return array(
       'name' => 'CSS Tools tests',
       'description' => '...',
-      'group' => 'Chaos Tools Suite',
+      'group' => 'ctools',
     );
   }
 
diff --git a/drupal7/sites/all/modules/ctools/tests/css_cache.test b/drupal7/sites/all/modules/ctools/tests/css_cache.test
index e289b42c..0b3528da 100644
--- a/drupal7/sites/all/modules/ctools/tests/css_cache.test
+++ b/drupal7/sites/all/modules/ctools/tests/css_cache.test
@@ -16,7 +16,7 @@ class CtoolsObjectCache extends DrupalWebTestCase {
     return array(
       'name' => 'Ctools CSS cache',
       'description' => 'Tests the custom CSS cache handler.',
-      'group' => 'Chaos Tools Suite',
+      'group' => 'ctools',
     );
   }
 
diff --git a/drupal7/sites/all/modules/ctools/tests/ctools.plugins.test b/drupal7/sites/all/modules/ctools/tests/ctools.plugins.test
index fe1829cf..7e866b16 100644
--- a/drupal7/sites/all/modules/ctools/tests/ctools.plugins.test
+++ b/drupal7/sites/all/modules/ctools/tests/ctools.plugins.test
@@ -12,7 +12,7 @@ class CtoolsPluginsGetInfoTestCase extends DrupalWebTestCase {
     return array(
       'name' => 'Get plugin info',
       'description' => 'Verify that plugin type definitions can properly set and overide values.',
-      'group' => 'Chaos Tools Suite',
+      'group' => 'ctools',
     );
   }
 
diff --git a/drupal7/sites/all/modules/ctools/tests/ctools_export_test/ctools_export.test b/drupal7/sites/all/modules/ctools/tests/ctools_export_test/ctools_export.test
index 1accfd74..6a062de7 100644
--- a/drupal7/sites/all/modules/ctools/tests/ctools_export_test/ctools_export.test
+++ b/drupal7/sites/all/modules/ctools/tests/ctools_export_test/ctools_export.test
@@ -14,7 +14,7 @@ class CtoolsExportCrudTestCase extends DrupalWebTestCase {
     return array(
       'name' => 'CTools export CRUD tests',
       'description' => 'Test the CRUD functionality for the ctools export system.',
-      'group' => 'Chaos Tools Suite',
+      'group' => 'ctools',
     );
   }
 
diff --git a/drupal7/sites/all/modules/ctools/tests/ctools_export_test/ctools_export_test.info b/drupal7/sites/all/modules/ctools/tests/ctools_export_test/ctools_export_test.info
index f2d96edc..1f2612ee 100644
--- a/drupal7/sites/all/modules/ctools/tests/ctools_export_test/ctools_export_test.info
+++ b/drupal7/sites/all/modules/ctools/tests/ctools_export_test/ctools_export_test.info
@@ -8,9 +8,9 @@ hidden = TRUE
 
 files[] = ctools_export.test
 
-; Information added by Drupal.org packaging script on 2016-10-16
-version = "7.x-1.11"
+; Information added by Drupal.org packaging script on 2016-11-22
+version = "7.x-1.12"
 core = "7.x"
 project = "ctools"
-datestamp = "1476581654"
+datestamp = "1479787162"
 
diff --git a/drupal7/sites/all/modules/ctools/tests/ctools_plugin_test.info b/drupal7/sites/all/modules/ctools/tests/ctools_plugin_test.info
index bd906122..4a6d2766 100644
--- a/drupal7/sites/all/modules/ctools/tests/ctools_plugin_test.info
+++ b/drupal7/sites/all/modules/ctools/tests/ctools_plugin_test.info
@@ -12,9 +12,9 @@ files[] = math_expression.test
 files[] = math_expression_stack.test
 hidden = TRUE
 
-; Information added by Drupal.org packaging script on 2016-10-16
-version = "7.x-1.11"
+; Information added by Drupal.org packaging script on 2016-11-22
+version = "7.x-1.12"
 core = "7.x"
 project = "ctools"
-datestamp = "1476581654"
+datestamp = "1479787162"
 
diff --git a/drupal7/sites/all/modules/ctools/tests/math_expression.test b/drupal7/sites/all/modules/ctools/tests/math_expression.test
index 730e079a..8810e8c4 100644
--- a/drupal7/sites/all/modules/ctools/tests/math_expression.test
+++ b/drupal7/sites/all/modules/ctools/tests/math_expression.test
@@ -13,7 +13,7 @@ class CtoolsMathExpressionTestCase extends DrupalWebTestCase {
     return array(
       'name' => 'CTools math expression tests',
       'description' => 'Test the math expression library of ctools.',
-      'group' => 'Chaos Tools Suite',
+      'group' => 'ctools',
     );
   }
 
diff --git a/drupal7/sites/all/modules/ctools/tests/math_expression_stack.test b/drupal7/sites/all/modules/ctools/tests/math_expression_stack.test
index 8143a55b..bdd46959 100644
--- a/drupal7/sites/all/modules/ctools/tests/math_expression_stack.test
+++ b/drupal7/sites/all/modules/ctools/tests/math_expression_stack.test
@@ -13,7 +13,7 @@ class CtoolsMathExpressionStackTestCase extends DrupalWebTestCase {
     return array(
       'name' => 'CTools math expression stack tests',
       'description' => 'Test the stack class of the math expression library.',
-      'group' => 'Chaos Tools Suite',
+      'group' => 'ctools',
     );
   }
 
diff --git a/drupal7/sites/all/modules/ctools/tests/object_cache.test b/drupal7/sites/all/modules/ctools/tests/object_cache.test
index 8791d7e7..2e714d6b 100644
--- a/drupal7/sites/all/modules/ctools/tests/object_cache.test
+++ b/drupal7/sites/all/modules/ctools/tests/object_cache.test
@@ -12,7 +12,7 @@ class CtoolsObjectCache extends DrupalWebTestCase {
     return array(
       'name' => 'Ctools object cache storage',
       'description' => 'Verify that objects are written, readable and lockable.',
-      'group' => 'Chaos Tools Suite',
+      'group' => 'ctools',
     );
   }
 
diff --git a/drupal7/sites/all/modules/ctools/views_content/views_content.info b/drupal7/sites/all/modules/ctools/views_content/views_content.info
index 84e2ae55..4f78dbdd 100644
--- a/drupal7/sites/all/modules/ctools/views_content/views_content.info
+++ b/drupal7/sites/all/modules/ctools/views_content/views_content.info
@@ -10,9 +10,9 @@ files[] = plugins/views/views_content_plugin_display_ctools_context.inc
 files[] = plugins/views/views_content_plugin_display_panel_pane.inc
 files[] = plugins/views/views_content_plugin_style_ctools_context.inc
 
-; Information added by Drupal.org packaging script on 2016-10-16
-version = "7.x-1.11"
+; Information added by Drupal.org packaging script on 2016-11-22
+version = "7.x-1.12"
 core = "7.x"
 project = "ctools"
-datestamp = "1476581654"
+datestamp = "1479787162"
 
diff --git a/drupal7/sites/all/modules/media/media.info b/drupal7/sites/all/modules/media/media.info
index 596e2ad1..4df40a9e 100644
--- a/drupal7/sites/all/modules/media/media.info
+++ b/drupal7/sites/all/modules/media/media.info
@@ -24,9 +24,9 @@ configure = admin/config/media/browser
 ; We have to add a fake version so Git checkouts do not fail Media dependencies
 version = 7.x-2.x-dev
 
-; Information added by Drupal.org packaging script on 2016-11-15
-version = "7.x-2.0-beta7"
+; Information added by Drupal.org packaging script on 2016-11-20
+version = "7.x-2.0-beta9"
 core = "7.x"
 project = "media"
-datestamp = "1479212995"
+datestamp = "1479647342"
 
diff --git a/drupal7/sites/all/modules/media/modules/media_bulk_upload/media_bulk_upload.info b/drupal7/sites/all/modules/media/modules/media_bulk_upload/media_bulk_upload.info
index 58b00280..08843c2b 100644
--- a/drupal7/sites/all/modules/media/modules/media_bulk_upload/media_bulk_upload.info
+++ b/drupal7/sites/all/modules/media/modules/media_bulk_upload/media_bulk_upload.info
@@ -13,9 +13,9 @@ test_dependencies[] = plupload
 files[] = includes/MediaBrowserBulkUpload.inc
 files[] = tests/media_bulk_upload.test
 
-; Information added by Drupal.org packaging script on 2016-11-15
-version = "7.x-2.0-beta7"
+; Information added by Drupal.org packaging script on 2016-11-20
+version = "7.x-2.0-beta9"
 core = "7.x"
 project = "media"
-datestamp = "1479212995"
+datestamp = "1479647342"
 
diff --git a/drupal7/sites/all/modules/media/modules/media_internet/media_internet.info b/drupal7/sites/all/modules/media/modules/media_internet/media_internet.info
index adb3d309..e740423b 100644
--- a/drupal7/sites/all/modules/media/modules/media_internet/media_internet.info
+++ b/drupal7/sites/all/modules/media/modules/media_internet/media_internet.info
@@ -12,9 +12,9 @@ files[] = includes/MediaInternetNoHandlerException.inc
 files[] = includes/MediaInternetValidationException.inc
 files[] = tests/media_internet.test
 
-; Information added by Drupal.org packaging script on 2016-11-15
-version = "7.x-2.0-beta7"
+; Information added by Drupal.org packaging script on 2016-11-20
+version = "7.x-2.0-beta9"
 core = "7.x"
 project = "media"
-datestamp = "1479212995"
+datestamp = "1479647342"
 
diff --git a/drupal7/sites/all/modules/media/modules/media_internet/tests/media_internet_test.info b/drupal7/sites/all/modules/media/modules/media_internet/tests/media_internet_test.info
index 6037a237..f3cbaef3 100644
--- a/drupal7/sites/all/modules/media/modules/media_internet/tests/media_internet_test.info
+++ b/drupal7/sites/all/modules/media/modules/media_internet/tests/media_internet_test.info
@@ -7,9 +7,9 @@ hidden = TRUE
 files[] = includes/MediaInternetTestStreamWrapper.inc
 files[] = includes/MediaInternetTestHandler.inc
 
-; Information added by Drupal.org packaging script on 2016-11-15
-version = "7.x-2.0-beta7"
+; Information added by Drupal.org packaging script on 2016-11-20
+version = "7.x-2.0-beta9"
 core = "7.x"
 project = "media"
-datestamp = "1479212995"
+datestamp = "1479647342"
 
diff --git a/drupal7/sites/all/modules/media/modules/media_migrate_file_types/media_migrate_file_types.info b/drupal7/sites/all/modules/media/modules/media_migrate_file_types/media_migrate_file_types.info
index 8a7bb55d..5579a471 100644
--- a/drupal7/sites/all/modules/media/modules/media_migrate_file_types/media_migrate_file_types.info
+++ b/drupal7/sites/all/modules/media/modules/media_migrate_file_types/media_migrate_file_types.info
@@ -8,9 +8,9 @@ dependencies[] = media
 
 configure = admin/structure/file-types/upgrade
 
-; Information added by Drupal.org packaging script on 2016-11-15
-version = "7.x-2.0-beta7"
+; Information added by Drupal.org packaging script on 2016-11-20
+version = "7.x-2.0-beta9"
 core = "7.x"
 project = "media"
-datestamp = "1479212995"
+datestamp = "1479647342"
 
diff --git a/drupal7/sites/all/modules/media/modules/media_wysiwyg/includes/media_wysiwyg.features.inc b/drupal7/sites/all/modules/media/modules/media_wysiwyg/includes/media_wysiwyg.features.inc
new file mode 100644
index 00000000..8bad2d7e
--- /dev/null
+++ b/drupal7/sites/all/modules/media/modules/media_wysiwyg/includes/media_wysiwyg.features.inc
@@ -0,0 +1,208 @@
+<?php
+
+/**
+ * @file
+ * Functions related to features integration.
+ */
+
+/**
+ * Implements hook_features_api().
+ */
+function media_wysiwyg_features_api() {
+  return array(
+    'media_wysiwyg' => array(
+      'name' => t('Media WYSIWYG'),
+      'feature_source' => TRUE,
+      'default_hook' => 'media_wysiwyg_defaults',
+      'default_file' => FEATURES_DEFAULTS_INCLUDED,
+    ),
+  );
+}
+
+/**
+ * Implements hook_features_export_options().
+ *
+ * Defines what shows up in the feature creation interface
+ */
+function media_wysiwyg_features_export_options() {
+  $options = array();
+  $entity_info = entity_get_info('file');
+  foreach ($entity_info['bundles'] as $file_type => $file_type_info) {
+    $file_type_label = check_plain($file_type_info['label']);
+    $options[$file_type . '_wysiwyg_view_mode'] =
+      t('@file_type WYSIWYG view mode', array('@file_type' => $file_type_label));
+
+    $view_mode_settings = field_view_mode_settings('file', $file_type);
+    foreach ($entity_info['view modes'] as $view_mode => $view_mode_info) {
+      if (!empty($view_mode_settings[$view_mode]['custom_settings'])) {
+        $options[$file_type . '_' . $view_mode . '_restrict_wysiwyg'] =
+          t('@file_type view mode restriction: @view_mode',
+          array('@file_type' => $file_type_label, '@view_mode' => $view_mode_info['label']));
+      }
+    }
+    // Add default option.
+    $options[$file_type . '_default_restrict_wysiwyg'] =
+      t('@file_type view mode restriction: Default',  array(
+        '@file_type' => $file_type_label,
+      ));
+  }
+  return $options;
+}
+
+/**
+ * Implements hook_features_export().
+ */
+function media_wysiwyg_features_export($data, &$export, $module_name = '') {
+  $export['dependencies']['media_wysiwyg'] = 'media_wysiwyg';
+
+  $entity_info = entity_get_info('file');
+  foreach ($entity_info['bundles'] as $file_type => $file_type_info) {
+
+    // Export the wysiwyg view mode setting for the file type.
+    $mode_data_key = $file_type . '_wysiwyg_view_mode';
+    if (in_array($mode_data_key, $data, TRUE)) {
+      $view_mode = _media_wysiwyg_get_wysiwyg_mode($file_type);
+      $export['features']['media_wysiwyg'][$mode_data_key] = $mode_data_key;
+    }
+    // Export the restricted view modes for the file type.
+    $view_modes = array_keys($entity_info['view modes']);
+    array_push($view_modes, 'default');
+    foreach ($view_modes as $view_mode) {
+      $restrict_data_key = $file_type . '_' . $view_mode . '_restrict_wysiwyg';
+      if (in_array($restrict_data_key, $data, TRUE)) {
+        $export['features']['media_wysiwyg'][$restrict_data_key] = $restrict_data_key;
+      }
+    }
+  }
+}
+
+/**
+ * Implements hook_features_export_render().
+ */
+function media_wysiwyg_features_export_render($module_name = '', $data, $export = NULL) {
+  $code = array();
+  $code[] = '  $media_wysiwyg = array();';
+  $code[] = '';
+
+  $entity_info = entity_get_info('file');
+  foreach ($entity_info['bundles'] as $file_type => $file_type_info) {
+
+    // Render the wysiwyg view mode setting for the file type.
+    $mode_data_key = $file_type . '_wysiwyg_view_mode';
+    if (array_key_exists($mode_data_key, $data) || in_array($mode_data_key, $data, TRUE)) {
+      $view_mode = _media_wysiwyg_get_wysiwyg_mode($file_type);
+      $view_mode_export =  (!empty($view_mode) ? features_var_export($view_mode) : "'none'");
+      $code[] = "  // WYSIWYG view mode for $file_type files.";
+      $code[] = "  \$media_wysiwyg['{$mode_data_key}'] = {$view_mode_export};";
+      $code[] = "";
+    }
+
+    // Export the restricted view modes for the file type.
+    $restriction_code = array();
+    $restricted_view_modes = _media_wysiwyg_get_restricted_modes($file_type);
+    $view_modes = array_keys($entity_info['view modes']);
+    array_push($view_modes, 'default');
+    foreach ($view_modes as $view_mode) {
+      $restrict_data_key = $file_type . '_' . $view_mode . '_restrict_wysiwyg';
+      if (array_key_exists($restrict_data_key, $data) || in_array($restrict_data_key, $data, TRUE)) {
+        $displays_export = in_array($view_mode, $restricted_view_modes) ? 'TRUE' : 'FALSE';
+        $restriction_code[] = "  \$media_wysiwyg['{$restrict_data_key}'] = {$displays_export};";
+      }
+    }
+    if (!empty($restriction_code)) {
+      array_unshift($restriction_code, "  // Restricted view modes for $file_type files.");
+      $restriction_code[] = "";
+      $code = array_merge($code, $restriction_code);
+    }
+  }
+
+  $code[] = '  return $media_wysiwyg;';
+  $code = implode("\n", $code);
+
+  return array('media_wysiwyg_defaults' => $code);
+}
+
+/**
+ * Implements hook_features_revert().
+ */
+function media_wysiwyg_features_revert($module) {
+  if ($defaults = features_get_default('media_wysiwyg', $module)) {
+
+    $entity_info = entity_get_info('file');
+    foreach ($entity_info['bundles'] as $file_type => $file_type_info) {
+
+      $mode_data_key = $file_type . '_wysiwyg_view_mode';
+      if (isset($defaults[$mode_data_key])) {
+        $view_mode = $defaults[$mode_data_key];
+        db_delete('media_view_mode_wysiwyg')
+          ->condition('type', $file_type)
+          ->execute();
+        if ($view_mode != 'none') {
+          $record = array('type' => $file_type, 'view_mode' => $view_mode);
+          drupal_write_record('media_view_mode_wysiwyg', $record);
+        }
+      }
+
+      $view_modes = array_keys($entity_info['view modes']);
+      array_push($view_modes, 'default');
+      foreach ($view_modes as $view_mode) {
+        $restrict_data_key = $file_type . '_' . $view_mode . '_restrict_wysiwyg';
+        if (isset($defaults[$restrict_data_key])) {
+          db_delete('media_restrict_wysiwyg')
+            ->condition('type', $file_type)
+            ->condition('display', $view_mode)
+            ->execute();
+          if ($defaults[$restrict_data_key]) {
+            $record = array(
+              'type' => $file_type,
+              'display' => $view_mode);
+            drupal_write_record('media_restrict_wysiwyg', $record);
+          }
+        }
+      }
+    }
+  }
+}
+
+/**
+ * Implements hook_features_rebuild().
+ */
+function media_wysiwyg_features_rebuild($module) {
+  media_wysiwyg_features_revert($module);
+}
+
+/**
+ * Implements hook_features_enable_feature().
+ */
+function media_wysiwyg_features_enable_feature($module) {
+  media_wysiwyg_features_revert($module);
+}
+
+/**
+ * Retrieve the WYSIWYG view mode for the specified file type.
+ *
+ * @param string $file_type
+ *   The machine name of the file type.
+ */
+function _media_wysiwyg_get_wysiwyg_mode($file_type) {
+  $view_mode = db_query(
+    'SELECT view_mode FROM {media_view_mode_wysiwyg} WHERE type = :type',
+    array(':type' => $file_type))
+    ->fetchField();
+  return $view_mode;
+}
+
+/**
+ * Retrieve a list of view modes that should not be available in the WYSIWYG for
+ * the specified file type.
+ *
+ * @param string $file_type
+ *   The machine name of the file type.
+ */
+function _media_wysiwyg_get_restricted_modes($file_type) {
+  $restricted_view_modes = db_query(
+    'SELECT display FROM {media_restrict_wysiwyg} WHERE type = :type',
+    array(':type' => $file_type))
+    ->fetchCol();
+  return $restricted_view_modes;
+}
diff --git a/drupal7/sites/all/modules/media/modules/media_wysiwyg/includes/media_wysiwyg.filter.inc b/drupal7/sites/all/modules/media/modules/media_wysiwyg/includes/media_wysiwyg.filter.inc
index 846b21b9..2370808e 100644
--- a/drupal7/sites/all/modules/media/modules/media_wysiwyg/includes/media_wysiwyg.filter.inc
+++ b/drupal7/sites/all/modules/media/modules/media_wysiwyg/includes/media_wysiwyg.filter.inc
@@ -5,7 +5,7 @@
  * Functions related to the WYSIWYG editor and the media input filter.
  */
 
-define('MEDIA_WYSIWYG_TOKEN_REGEX', '/\[\[\{"fid".*?\]\]/s');
+define('MEDIA_WYSIWYG_TOKEN_REGEX', '/\[\[.*?\]\]/s');
 
 /**
  * Filter callback for media markup filter.
@@ -215,11 +215,21 @@ function media_wysiwyg_token_to_markup($match, $wysiwyg = FALSE, $langcode = NUL
 
   if ($wysiwyg) {
     $settings['wysiwyg'] = $wysiwyg;
+
+    // Render file in WYSIWYG using appropriate view mode.
+    $view_mode = db_query('SELECT view_mode FROM {media_view_mode_wysiwyg} WHERE type = :type', array(
+      ':type' => $file->type,
+    ))
+      ->fetchField();
+    if (empty($view_mode)) {
+      $view_mode = $tag_info['view_mode'];
+    }
+
     // If sending markup to a WYSIWYG, we need to pass the file information so
     // that an inline macro can be generated when the WYSIWYG is detached.
     // The WYSIWYG plugin is expecting this information in the
     // Drupal.settings.mediaDataMap variable.
-    $element = media_wysiwyg_get_file_without_label($file, $tag_info['view_mode'], $settings, $langcode);
+    $element = media_wysiwyg_get_file_without_label($file, $view_mode, $settings, $langcode);
     $data = array(
       'type' => 'media',
       'fid'  => $file->fid,
@@ -257,13 +267,13 @@ function media_wysiwyg_token_to_markup($match, $wysiwyg = FALSE, $langcode = NUL
     }
     if (count(element_children($element['content'])) > 1) {
       // Add surrounding divs to group them together.
-      // We dont want divs when there are no additional fields to allow files
+      // We don't want divs when there are no additional fields to allow files
       // to display inline with text, without breaking p tags.
       $element['content']['#type'] = 'container';
       $element['content']['#attributes']['class'] = array(
         'media',
         'media-element-container',
-        'media-' . $element['content']['file']['#view_mode']
+        'media-' . $element['content']['file']['#view_mode'],
       );
     }
 
@@ -351,7 +361,7 @@ function _media_wysiwyg_generate_tagMap($text) {
   // between function calls. Since media_process_form is multiple times
   // with same form, this function is also called multiple times.
   static $tagmap = array();
-  preg_match_all(MEDIA_WYSIWYG_TOKEN_REGEX, $text, $matches, PREG_SET_ORDER);
+  preg_match_all("/\[\[.*?\]\]/s", $text, $matches, PREG_SET_ORDER);
   foreach ($matches as $match) {
     // We see if tagContent is already in $tagMap, if not we add it
     // to $tagmap.  If we return an empty array, we break embeddings of the same
@@ -415,12 +425,23 @@ function media_wysiwyg_get_wysiwyg_allowed_view_modes($file) {
   }
 
   $view_modes = $enabled_view_modes[$file->type];
+  media_wysiwyg_wysiwyg_allowed_view_modes_restrict($view_modes, $file);
   drupal_alter('media_wysiwyg_allowed_view_modes', $view_modes, $file);
   // Invoke the deprecated/misspelled alter hook as well.
   drupal_alter('media_wysiwyg_wysiwyg_allowed_view_modes', $view_modes, $file);
   return $view_modes;
 }
-
+/**
+ * Do not show restricted view modes.
+ */
+function media_wysiwyg_wysiwyg_allowed_view_modes_restrict(&$view_modes, &$file) {
+  $restricted_view_modes = db_query('SELECT display FROM {media_restrict_wysiwyg} WHERE type = :type', array(':type' => $file->type))->fetchCol();
+  foreach ($restricted_view_modes as $restricted_view_mode) {
+    if (array_key_exists($restricted_view_mode, $view_modes)) {
+      unset($view_modes[$restricted_view_mode]);
+    }
+  }
+}
 /**
  * #pre_render callback: Modify the element if the render cache is filtered.
  */
diff --git a/drupal7/sites/all/modules/media/modules/media_wysiwyg/includes/media_wysiwyg.pages.inc b/drupal7/sites/all/modules/media/modules/media_wysiwyg/includes/media_wysiwyg.pages.inc
index 4f30d8aa..482947d8 100644
--- a/drupal7/sites/all/modules/media/modules/media_wysiwyg/includes/media_wysiwyg.pages.inc
+++ b/drupal7/sites/all/modules/media/modules/media_wysiwyg/includes/media_wysiwyg.pages.inc
@@ -97,6 +97,9 @@ function media_wysiwyg_format_form($form, &$form_state, $file) {
     $form['options']['fields'][$field_name]['#access'] = $allow;
   }
 
+  // Add view mode preview.
+  media_wysiwyg_format_form_view_mode($form, $form_state, $file);
+
   // Similar to a form_alter, but we want this to run first so that
   // media.types.inc can add the fields specific to a given type (like alt tags
   // on media). If implemented as an alter, this might not happen, making other
@@ -110,3 +113,77 @@ function media_wysiwyg_format_form($form, &$form_state, $file) {
 
   return $form;
 }
+
+/**
+ * Add ajax preview when selecting view mode in wysiwyg editor.
+ */
+function media_wysiwyg_format_form_view_mode(&$form, $form_state, $file)  {
+  // Check to see if a view mode ("format") has already been specified for
+  //  this media item. First, check for a standard form-submitted value.
+  if (!empty($form_state['values']['format'])) {
+    $view_mode = $form_state['values']['format'];
+  }
+  // Second, check the request for a JSON-encoded value.
+  elseif (isset($_GET['fields'])) {
+    $query_fields = drupal_json_decode($_GET['fields']);
+    if (isset($query_fields['format'])) {
+      $view_mode = $query_fields['format'];
+    }
+  }
+  // If we were unable to determine a view mode, or we found a view mode
+  //  that does not exist in the list of format options presented on this
+  //  form, use the default view mode.
+  if (!isset($view_mode) || !array_key_exists($view_mode, $form['options']['format']['#options'])) {
+    $view_mode = variable_get('media_wysiwyg_wysiwyg_default_view_mode', 'full');
+  }
+
+  $form['preview'] = array();
+  $form['preview']['#prefix'] = '<div class="media-item"><div class="media-thumbnail">';
+  $form['preview']['#suffix'] = '</div><div class="label-wrapper"><label class="media-filename">' . $file->filename . '</label></div></div>';
+  $form['preview']['thumbnail'] = file_view_file($file, $view_mode);
+  $form['preview']['thumbnail']['#prefix'] = '<div id="media-preview">';
+  $form['preview']['thumbnail']['#suffix'] = '</div>';
+
+  if (!isset($form['options']['format']['#default_value'])) {
+    $form['options']['format']['#default_value'] = $view_mode;
+  }
+  $form['options']['format']['#ajax'] = array(
+    'callback' => 'media_wysiwyg_format_form_preview',
+    'wrapper' => 'media-preview',
+  );
+
+  $wysiwyg_view_mode = db_query('SELECT view_mode FROM {media_view_mode_wysiwyg} WHERE type = :type', array(':type' => $file->type))->fetchField();
+  $view_modes = media_wysiwyg_get_wysiwyg_allowed_view_modes($file);
+  $formats = $options = array();
+
+  foreach ($view_modes as $view_mode => $view_mode_info) {
+    $options[$view_mode] = $view_mode_info['label'];
+
+    if (!empty($wysiwyg_view_mode)) {
+      $element = media_wysiwyg_get_file_without_label($file, $wysiwyg_view_mode, array('wysiwyg' => TRUE));
+    }
+    else {
+      $element = media_wysiwyg_get_file_without_label($file, $view_mode, array('wysiwyg' => TRUE));
+    }
+
+    $formats[$view_mode] = drupal_render($element);
+  }
+
+  $form['#formats'] = $formats;
+  $form['options']['format']['#options'] = $options;
+}
+
+/**
+ * AJAX callback to select the portion of the format form to be updated with a preview.
+ *
+ * @param array $form
+ *   An associative array containing the structure of the form.
+ * @param array $form_state
+ *   An associative array containing the current state of the form.
+ *
+ * @return array
+ *   The preview form item.
+ */
+function media_wysiwyg_format_form_preview($form, $form_state) {
+  return $form['preview']['thumbnail'];
+}
diff --git a/drupal7/sites/all/modules/media/modules/media_wysiwyg/media_wysiwyg.info b/drupal7/sites/all/modules/media/modules/media_wysiwyg/media_wysiwyg.info
index efda302f..afd892bb 100644
--- a/drupal7/sites/all/modules/media/modules/media_wysiwyg/media_wysiwyg.info
+++ b/drupal7/sites/all/modules/media/modules/media_wysiwyg/media_wysiwyg.info
@@ -15,9 +15,9 @@ files[] = tests/media_wysiwyg.macro.test
 
 configure = admin/config/media/browser
 
-; Information added by Drupal.org packaging script on 2016-11-15
-version = "7.x-2.0-beta7"
+; Information added by Drupal.org packaging script on 2016-11-20
+version = "7.x-2.0-beta9"
 core = "7.x"
 project = "media"
-datestamp = "1479212995"
+datestamp = "1479647342"
 
diff --git a/drupal7/sites/all/modules/media/modules/media_wysiwyg/media_wysiwyg.install b/drupal7/sites/all/modules/media/modules/media_wysiwyg/media_wysiwyg.install
index d02a3b22..34d30c23 100644
--- a/drupal7/sites/all/modules/media/modules/media_wysiwyg/media_wysiwyg.install
+++ b/drupal7/sites/all/modules/media/modules/media_wysiwyg/media_wysiwyg.install
@@ -5,6 +5,52 @@
  * Install, update and uninstall functions for the Media WYSIWYG module.
  */
 
+ /**
+ * Implements hook_schema().
+ */
+function media_wysiwyg_schema() {
+  $schema['media_restrict_wysiwyg'] = array(
+    'description' => 'Stores media displays restricted in wysiwyg.',
+    'fields' => array(
+      'type' => array(
+        'description' => 'The machine name of the file type.',
+        'type' => 'varchar',
+        'length' => 255,
+        'not null' => TRUE,
+        'default' => '',
+      ),
+      'display' => array(
+        'description' => 'The restricted display.',
+        'type' => 'varchar',
+        'length' => '255',
+        'not null' => TRUE,
+        'default' => '',
+      ),
+    ),
+  );
+  $schema['media_view_mode_wysiwyg'] = array(
+    'description' => 'Maps WYSIWYG view modes to file types.',
+    'fields' => array(
+      'type' => array(
+        'description' => 'The machine name of the file type.',
+        'type' => 'varchar',
+        'length' => 255,
+        'not null' => TRUE,
+        'default' => '',
+      ),
+      'view_mode' => array(
+        'description' => 'WYSIWYG view mode mapped to this file type.',
+        'type' => 'varchar',
+        'length' => 255,
+        'not null' => TRUE,
+        'default' => '',
+      ),
+
+    ),
+  );
+  return $schema;
+}
+
 /**
  * Implements hook_install().
  */
@@ -106,3 +152,49 @@ function media_wysiwyg_update_7204() {
     ));
   }
 }
+
+/**
+ * Install {media_restrict_wysiwyg} and {media_view_mode_wysiwyg}.
+ *
+ * Remove variables media_wysiwyg_view_mode_%.
+ *
+ * Uninstall media_wysiwyg_view_mode module.
+ */
+function media_wysiwyg_update_7205() {
+  $schema = media_wysiwyg_schema();
+
+  if (!db_table_exists('media_restrict_wysiwyg')) {
+    db_create_table('media_restrict_wysiwyg',  $schema['media_restrict_wysiwyg']);
+    db_create_table('media_view_mode_wysiwyg', $schema['media_view_mode_wysiwyg']);
+  }
+
+  db_delete('variable')->condition('name', "media_wysiwyg_view_mode_%", "LIKE")->execute();
+
+  // Disable and uninstall View Mode module.Since the view mode module is
+  // deleted, this copies from  module_disable() and drupal_uninstall_modules().
+  // Disable first.
+  $module = 'media_wysiwyg_view_mode';
+  db_update('system')
+    ->fields(array('status' => 0))
+    ->condition('type', 'module')
+    ->condition('name', $module)
+    ->execute();
+  system_list_reset();
+  module_list(TRUE);
+  module_implements('', FALSE, TRUE);
+  entity_info_cache_clear();
+  // Invoke hook_modules_disabled before disabling modules,
+  // so we can still call module hooks to get information.
+  module_invoke_all('modules_disabled', array($module));
+  // Update the registry to remove the newly-disabled module.
+  registry_update();
+  _system_update_bootstrap_status();
+  // Update the theme registry to remove the newly-disabled module.
+  drupal_theme_rebuild();
+
+  // Now uninstall.
+  drupal_uninstall_schema($module);
+  drupal_set_installed_schema_version($module, SCHEMA_UNINSTALLED);
+
+  module_invoke_all('modules_uninstalled', array($module));
+}
diff --git a/drupal7/sites/all/modules/media/modules/media_wysiwyg/media_wysiwyg.module b/drupal7/sites/all/modules/media/modules/media_wysiwyg/media_wysiwyg.module
index 33db3b11..e031e33f 100644
--- a/drupal7/sites/all/modules/media/modules/media_wysiwyg/media_wysiwyg.module
+++ b/drupal7/sites/all/modules/media/modules/media_wysiwyg/media_wysiwyg.module
@@ -14,6 +14,9 @@ require_once dirname(__FILE__) . '/includes/media_wysiwyg.filter.inc';
 // Functions for UUID support to embedded media.
 require_once dirname(__FILE__) . '/includes/media_wysiwyg.uuid.inc';
 
+// Functions for features integration.
+require_once dirname(__FILE__) . '/includes/media_wysiwyg.features.inc';
+
 /**
  * Implements hook_hook_info().
  */
@@ -362,15 +365,15 @@ function media_wysiwyg_get_file_without_label($file, $view_mode, $settings = arr
     preg_match($pattern, $field_name, $matches);
     if (!empty($matches[2])) {
       $field_name = $matches[2];
-      $langcode = field_language('file', $file, $field_name);
-      if (isset($settings['fields'][$field_name][$langcode]['value'])) {
+      $field_langcode = field_language('file', $file, $field_name);
+      if (isset($settings['fields'][$field_name][$field_langcode]['value'])) {
         if (empty($settings['attributes'][$field_type])) {
-          $settings['attributes'][$field_type] = $settings['fields'][$field_name][$langcode]['value'];
+          $settings['attributes'][$field_type] = $settings['fields'][$field_name][$field_langcode]['value'];
         }
       }
-      if (isset($settings['fields'][$field_name][$langcode][0]['value'])) {
+      if (isset($settings['fields'][$field_name][$field_langcode][0]['value'])) {
         if (empty($settings['attributes'][$field_type])) {
-          $settings['attributes'][$field_type] = $settings['fields'][$field_name][$langcode][0]['value'];
+          $settings['attributes'][$field_type] = $settings['fields'][$field_name][$field_langcode][0]['value'];
         }
       }
     }
@@ -530,3 +533,114 @@ function media_wysiwyg_file_displays_alter(&$displays, $file, $view_mode) {
     }
   }
 }
+
+/**
+ * Implements hook_entity_info_alter().
+ *
+ * Add a file type named 'WYSIWYG'.
+ */
+function media_wysiwyg_entity_info_alter(&$entity_info) {
+  $entity_info['file']['view modes'] += array(
+    'wysiwyg' => array(
+      'label' => t('WYSIWYG'),
+      'custom settings' => TRUE,
+    ),
+  );
+}
+
+/**
+ * Implements hook_form_FORM_ID_alter().
+ *
+ * Add select when editing file types to set wysiwyg view mode.
+ */
+function media_wysiwyg_form_file_entity_file_type_form_alter(&$form, &$form_state) {
+  $options = array();
+
+  // Add an option allowing users not to use a view mode.
+  $options['none'] = t('None');
+
+  // Add the default view mode by default.
+  $options['default'] = t('Default');
+
+  $entity_info = entity_get_info('file');
+  foreach ($entity_info['view modes'] as $view_mode => $view_mode_info) {
+    $options[$view_mode] = check_plain($view_mode_info['label']);
+  }
+
+  $file_type = $form['#file_type']->type;
+  $view_mode = db_query('SELECT view_mode FROM {media_view_mode_wysiwyg} WHERE type = :type', array(':type' => $file_type))->fetchField();
+  $view_mode = empty($view_mode) ? 'none' : $view_mode;
+
+  $form['file_wysiwyg_view_mode'] = array(
+    '#type' => 'select',
+    '#title' => t('WYSIWYG view mode'),
+    '#options' => $options,
+    '#default_value' => $view_mode,
+    '#description' => t('View mode to be used when displaying files inside of the WYSIWYG editor.'),
+  );
+
+  // Move submit after our select box. There might be a better way to do this.
+  $form['submit']['#weight'] = 1;
+
+  array_unshift($form['#submit'], 'media_wysiwyg_form_file_entity_file_type_form_alter_submit');
+}
+
+/**
+ * Custom submit handler.
+ *
+ * Save wysiwyg view mode.
+ *
+ * @see media_wysiwyg_form_file_entity_file_type_form_alter().
+ */
+function media_wysiwyg_form_file_entity_file_type_form_alter_submit(&$form, &$form_state) {
+  $file_type = $form['#file_type']->type;
+  $view_mode = $form_state['values']['file_wysiwyg_view_mode'];
+  db_delete('media_view_mode_wysiwyg')->condition('type', $file_type)->execute();
+  if ($view_mode != 'none') {
+    $record = array('type' => $file_type, 'view_mode' => $view_mode);
+    drupal_write_record('media_view_mode_wysiwyg', $record);
+  }
+}
+
+/**
+ * Implements hook_form_FORM_ID_alter().
+ *
+ * Add checkbox to restrict file type view mode availability in wysiwyg.
+ */
+function media_wysiwyg_form_file_entity_file_display_form_alter(&$form, &$form_state) {
+  $file_type = $form['#file_type'];
+  $view_mode = $form['#view_mode'];
+
+  if ($view_mode != 'none') {
+    $restricted = db_query(
+      'SELECT 1 FROM {media_restrict_wysiwyg} WHERE type = :type and display = :display',
+      array(':type' => $file_type, ':display' => $view_mode)
+    )->fetchField();
+    $form['restrict_wysiwyg'] = array(
+      '#type' => 'checkbox',
+      '#title' => t('Restrict in WYSIWYG'),
+      '#description' => t('If checked, then this mode will not be allowed from the WYSIWYG.'),
+      '#default_value' => !empty($restricted),
+    );
+    array_unshift($form['#submit'], 'media_wysiwyg_form_file_entity_file_display_form_alter_submit');
+  }
+
+  return $form;
+}
+
+/**
+ * Custom submit handler.
+ *
+ * Save restricted wysiwyg file types.
+ *
+ * @see media_wysiwyg_form_file_entity_file_display_form_alter().
+ */
+function media_wysiwyg_form_file_entity_file_display_form_alter_submit(&$form, &$form_state) {
+  $file_type = $form['#file_type'];
+  $view_mode = $form['#view_mode'];
+  db_delete('media_restrict_wysiwyg')->condition('type', $file_type)->condition('display', $view_mode)->execute();
+  if (!empty($form_state['values']['restrict_wysiwyg'])) {
+    $record = array('type' => $file_type, 'display' => $view_mode);
+    drupal_write_record('media_restrict_wysiwyg', $record);
+  }
+}
diff --git a/drupal7/sites/all/modules/media/modules/media_wysiwyg/media_wysiwyg.test b/drupal7/sites/all/modules/media/modules/media_wysiwyg/media_wysiwyg.test
index b66dc68a..6b0aaa37 100644
--- a/drupal7/sites/all/modules/media/modules/media_wysiwyg/media_wysiwyg.test
+++ b/drupal7/sites/all/modules/media/modules/media_wysiwyg/media_wysiwyg.test
@@ -99,3 +99,89 @@ abstract class MediaWYSIWYGTestHelper extends DrupalWebTestCase {
   }
 
 }
+
+/**
+ * Defines base class for media_wysiwyg_view_mode test cases.
+ */
+class MediaWYSIWYGViewModeTestHelper extends MediaWYSIWYGTestHelper {
+  function setUp() {
+    parent::setUp();
+
+    $web_user = $this->drupalCreateUser(array('access administration pages', 'administer file types', 'view files', 'use media wysiwyg'));
+    $this->drupalLogin($web_user);
+  }
+}
+
+/**
+ * Test configuring view modes available on the format form.
+ */
+class FormatFormViewModesTest extends MediaWYSIWYGViewModeTestHelper {
+  public static function getInfo() {
+    return array(
+      'name' => 'Format Form WYSIWYG View Modes',
+      'description' => 'Test configuring view modes available on the format form.',
+      'group' => 'Media WYSIWYG',
+    );
+  }
+
+  function setUp() {
+    parent::setUp();
+  }
+
+  /**
+   * Configure format form view mode restrictions and ensure that they are followed.
+   */
+  function testAllowedFormatFormViewModes() {
+    // Create an image file to test with.
+    $files = $this->drupalGetTestFiles('image');
+    $files[0]->status = FILE_STATUS_PERMANENT;
+    $file = file_save($files[0]);
+    $fid = $file->fid;
+
+    // Teaser view mode should be selectable.
+    $this->drupalGet('media/' . $fid . '/format-form');
+    $this->assertResponse(200);
+    $this->assertOption('edit-format', 'teaser');
+
+    // Restrict the use of the default view mode.
+    $this->drupalGet('admin/structure/file-types/manage/image/file-display/teaser');
+    $this->assertResponse(200);
+    $edit = array(
+      'restrict_wysiwyg' => 1,
+    );
+    $this->drupalPost(NULL, $edit, t('Save configuration'));
+    $this->assertResponse(200);
+
+    // Teaser view mode should be restricted.
+    $this->drupalGet('media/' . $fid . '/format-form');
+    $this->assertResponse(200);
+    $this->assertNoOption('edit-format', 'teaser');
+  }
+
+  /**
+   * Assert that a select option in the current page exists.
+   *
+   * @param $id
+   *   id of select field to assert.
+   * @param $option
+   *   Option to assert.
+   */
+  function assertOption($id, $option, $message = '', $group = 'Browser') {
+    $options = $this->xpath('//select[@id=:id]/option[@value=:option]', array(':id' => $id, ':option' => $option));
+    return $this->assertTrue(isset($options[0]), $message ? $message : t('Option @option for field @id exists.', array('@option' => $option, '@id' => $id)));
+  }
+
+  /**
+   * Assert that a select option in the current page does not exist.
+   *
+   * @param $id
+   *   id of select field to assert.
+   * @param $option
+   *   Option to assert.
+   */
+  function assertNoOption($id, $option, $message = '', $group = 'Browser') {
+    $options = $this->xpath('//select[@id=:id]/option[@value=:option]', array(':id' => $id, ':option' => $option));
+    return $this->assertFalse(isset($options[0]), $message ? $message : t('Option @option for field @id does not exist.', array('@option' => $option, '@id' => $id)));
+  }
+
+}
diff --git a/drupal7/sites/all/modules/media/modules/media_wysiwyg_view_mode/media_wysiwyg_view_mode.info b/drupal7/sites/all/modules/media/modules/media_wysiwyg_view_mode/media_wysiwyg_view_mode.info
index 48592432..20469b12 100644
--- a/drupal7/sites/all/modules/media/modules/media_wysiwyg_view_mode/media_wysiwyg_view_mode.info
+++ b/drupal7/sites/all/modules/media/modules/media_wysiwyg_view_mode/media_wysiwyg_view_mode.info
@@ -1,13 +1,11 @@
 name = Media WYSIWYG View Mode
-description = Enables files inside of the WYSIWYG editor to be displayed using a separate view mode.
+description = DEPRECATED, this folder is only here so that the module can be uninstalled.
 package = Media
 core = 7.x
-dependencies[] = media_wysiwyg
-files[] = media_wysiwyg_view_mode.test
 
-; Information added by Drupal.org packaging script on 2016-11-15
-version = "7.x-2.0-beta7"
+; Information added by Drupal.org packaging script on 2016-11-20
+version = "7.x-2.0-beta9"
 core = "7.x"
 project = "media"
-datestamp = "1479212995"
+datestamp = "1479647342"
 
diff --git a/drupal7/sites/all/modules/media/modules/media_wysiwyg_view_mode/media_wysiwyg_view_mode.install b/drupal7/sites/all/modules/media/modules/media_wysiwyg_view_mode/media_wysiwyg_view_mode.install
index 56b706fa..8288736a 100644
--- a/drupal7/sites/all/modules/media/modules/media_wysiwyg_view_mode/media_wysiwyg_view_mode.install
+++ b/drupal7/sites/all/modules/media/modules/media_wysiwyg_view_mode/media_wysiwyg_view_mode.install
@@ -9,7 +9,7 @@
  * Implements hook_uninstall().
  */
 function media_wysiwyg_view_mode_uninstall() {
-  db_delete('variable')
-    ->condition('name', "media_wysiwyg_view_mode_%", "LIKE")
-    ->execute();
+ db_delete('variable')
+ ->condition('name', "media_wysiwyg_view_mode_%", "LIKE")
+ ->execute();
 }
diff --git a/drupal7/sites/all/modules/media/modules/media_wysiwyg_view_mode/media_wysiwyg_view_mode.module b/drupal7/sites/all/modules/media/modules/media_wysiwyg_view_mode/media_wysiwyg_view_mode.module
index 997f1c5f..49f21c2e 100644
--- a/drupal7/sites/all/modules/media/modules/media_wysiwyg_view_mode/media_wysiwyg_view_mode.module
+++ b/drupal7/sites/all/modules/media/modules/media_wysiwyg_view_mode/media_wysiwyg_view_mode.module
@@ -1,155 +1,12 @@
 <?php
-
-/**
- * @file
- * Primarily Drupal hooks.
- */
-
-/**
- * Implements hook_entity_info_alter().
- */
-function media_wysiwyg_view_mode_entity_info_alter(&$entity_info) {
-  $entity_info['file']['view modes'] += array(
-    'wysiwyg' => array(
-      'label' => t('WYSIWYG'),
-      'custom settings' => TRUE,
-    ),
-  );
-}
-
-/**
- * Implements hook_media_wysiwyg_allowed_view_modes_alter().
+/***
+ * hook_help
  */
-function media_wysiwyg_view_mode_media_wysiwyg_allowed_view_modes_alter(&$view_modes, &$file) {
-  if (variable_get("media_wysiwyg_view_mode_{$file->type}_wysiwyg_restricted_view_modes_status")) {
-    $restricted_view_modes = variable_get("media_wysiwyg_view_mode_{$file->type}_wysiwyg_restricted_view_modes", array());
-    foreach ($restricted_view_modes as $restricted_view_mode) {
-      if (array_key_exists($restricted_view_mode, $view_modes)) {
-        unset($view_modes[$restricted_view_mode]);
-      }
-    }
-  }
-}
-
-/**
- * Implements hook_entity_view_mode_alter().
- */
-function media_wysiwyg_view_mode_entity_view_mode_alter(&$view_mode, $context) {
-  if ($context['entity_type'] == 'file' && !empty($context['entity']->override['wysiwyg'])) {
-    if (variable_get("media_wysiwyg_view_mode_{$context['entity']->type}_file_wysiwyg_view_mode_status")) {
-      $view_mode = variable_get("media_wysiwyg_view_mode_{$context['entity']->type}_file_wysiwyg_view_mode", 'wysiwyg');
-    }
-  }
-}
-
-/**
- * Implements hook_form_FORM_ID_alter().
- */
-function media_wysiwyg_view_mode_form_media_wysiwyg_format_form_alter(&$form, $form_state) {
-  // Check to see if a view mode ("format") has already been specified for
-  // this media item. First, check for a standard form-submitted value.
-  if (!empty($form_state['values']['format'])) {
-    $view_mode = $form_state['values']['format'];
-  }
-  // Second, check the request for a JSON-encoded value.
-  elseif (isset($_GET['fields'])) {
-    $query_fields = drupal_json_decode($_GET['fields']);
-    if (isset($query_fields['format'])) {
-      $view_mode = $query_fields['format'];
-    }
-  }
-  // If we were unable to determine a view mode, or we found a view mode
-  //  that does not exist in the list of format options presented on this
-  //  form, use the default view mode.
-  if (!isset($view_mode) || !array_key_exists($view_mode, $form['options']['format']['#options'])) {
-    $view_mode = $form['options']['format']['#default_value'];
-  }
-
-  // Display an actual preview instead of media_get_thumbnail_preview().
-  // @todo Should this code be merged up to media_wysiwyg_format_form?
-  $form['preview']['#prefix'] = '<div id="preview">';
-  $form['preview']['#suffix'] = '</div>';
-  $form['preview']['#markup'] = $form_state['storage']['view_mode_previews'][$view_mode];
-
-  // Change the preview when the user changes the format.
-  $form['options']['format']['#ajax'] = array(
-    'callback' => 'media_wysiwyg_view_mode_form_media_wysiwyg_format_form_preview',
-    'wrapper' => 'preview',
-  );
-}
-
-/**
- * AJAX callback to select the portion of the format form to be updated with a preview.
- *
- * @param array $form
- *   An associative array containing the structure of the form.
- * @param array $form_state
- *   An associative array containing the current state of the form.
- *
- * @return array
- *   The preview form item.
- */
-function media_wysiwyg_view_mode_form_media_wysiwyg_format_form_preview($form, $form_state) {
-  return $form['preview'];
-}
-
-/**
- * Implements hook_form_FORM_ID_alter().
- */
-function media_wysiwyg_view_mode_form_file_entity_file_type_form_alter(&$form, $form_state) {
-  $type = $form_state['build_info']['args'][0];
-  $view_mode_options = media_wysiwyg_get_file_type_view_mode_options($type->type);
-
-  $form['media_wysiwyg_view_mode'] = array(
-    '#type' => 'fieldset',
-    '#title' => t('Media WYSIWYG View Modes'),
-    '#collapsible' => TRUE,
-    '#collapsed' => TRUE,
-    '#tree' => TRUE,
-  );
-
-  $form['media_wysiwyg_view_mode']["media_wysiwyg_view_mode_{$type->type}_wysiwyg_restricted_view_modes_status"] = array(
-    '#type' => 'checkbox',
-    '#title' => t('Restrict allowed view modes when embedding with the WYSIWYG', array('%type' => $type->label)),
-    '#default_value' => variable_get("media_wysiwyg_view_mode_{$type->type}_wysiwyg_restricted_view_modes_status", FALSE),
-  );
-  $form['media_wysiwyg_view_mode']["media_wysiwyg_view_mode_{$type->type}_wysiwyg_restricted_view_modes"] = array(
-    '#type' => 'checkboxes',
-    '#title' => t('Select which view modes <em>cannot</em> be selected'),
-    '#options' => $view_mode_options,
-    '#default_value' => variable_get("media_wysiwyg_view_mode_{$type->type}_wysiwyg_restricted_view_modes", array()),
-    '#states' => array(
-      'visible' => array(
-        ':input[name="media_wysiwyg_view_mode[media_wysiwyg_view_mode_' . $type->type . '_wysiwyg_restricted_view_modes_status]"]' => array('checked' => TRUE),
-      ),
-    ),
-  );
-  $form['media_wysiwyg_view_mode']["media_wysiwyg_view_mode_{$type->type}_file_wysiwyg_view_mode_status"] = array(
-    '#type' => 'checkbox',
-    '#title' => t('Use a specific view mode when the file is previewed in the WYSIWYG'),
-    '#default_value' => variable_get("media_wysiwyg_view_mode_{$type->type}_file_wysiwyg_view_mode_status", 0),
-  );
-  $form['media_wysiwyg_view_mode']["media_wysiwyg_view_mode_{$type->type}_file_wysiwyg_view_mode"] = array(
-    '#type' => 'select',
-    '#title' => t('View mode to always use in the WYSIWYG'),
-    '#options' => $view_mode_options,
-    '#default_value' => variable_get("media_wysiwyg_view_mode_{$type->type}_file_wysiwyg_view_mode", 'wysiwyg'),
-    '#states' => array(
-      'visible' => array(
-        ':input[name="media_wysiwyg_view_mode[media_wysiwyg_view_mode_' . $type->type . '_file_wysiwyg_view_mode_status]"]' => array('checked' => TRUE),
-      ),
-    ),
-  );
-
-  $form['#submit'][] = 'media_wysiwyg_view_mode_form_file_entity_file_type_form_submit';
-}
+function media_wysiwyg_view_mode_help($path, $arg) {
+  switch ($path) {
+    // Main module help for the block module
+    case 'admin/help#media_wysiwyg_view_mode':
+      return '<p>' . t('The code that was previously in this module was moved to media_wysiwyg however to uninstall this module this has to be here.') . '</p>';
 
-function media_wysiwyg_view_mode_form_file_entity_file_type_form_submit($form, $form_state) {
-  $values = $form_state['values']['media_wysiwyg_view_mode'];
-  foreach ($values as $key => $value) {
-    if (is_array($value)) {
-      $value = array_filter($value);
-    }
-    variable_set($key, $value);
   }
 }
diff --git a/drupal7/sites/all/modules/media/modules/media_wysiwyg_view_mode/media_wysiwyg_view_mode.test b/drupal7/sites/all/modules/media/modules/media_wysiwyg_view_mode/media_wysiwyg_view_mode.test
deleted file mode 100644
index 0609e18b..00000000
--- a/drupal7/sites/all/modules/media/modules/media_wysiwyg_view_mode/media_wysiwyg_view_mode.test
+++ /dev/null
@@ -1,56 +0,0 @@
-<?php
-
-/**
- * @file
- * Tests for media_wysiwyg_view_mode.module.
- */
-
-/**
- * Defines base class for media_wysiwyg_view_mode test cases.
- */
-abstract class MediaWYSIWYGViewModeTestHelper extends MediaWYSIWYGTestHelper {
-  function setUp() {
-    parent::setUp(array('media_wysiwyg_view_mode'));
-
-    $web_user = $this->drupalCreateUser(array('view files', 'use media wysiwyg', 'administer file types'));
-    $this->drupalLogin($web_user);
-  }
-}
-
-/**
- * Test configuring view modes available on the format form.
- */
-class FormatFormViewModesTest extends MediaWYSIWYGViewModeTestHelper {
-  public static function getInfo() {
-    return array(
-      'name' => 'Format Form WYSIWYG View Modes',
-      'description' => 'Test configuring view modes available on the format form.',
-      'group' => 'Media WYSIWYG View Mode',
-    );
-  }
-
-  /**
-   * Configure format form view mode restrictions and ensure that they are followed.
-   */
-  function testAllowedFormatFormViewModes() {
-    // Create an image file to test with.
-    $files = $this->drupalGetTestFiles('image');
-    $files[0]->status = FILE_STATUS_PERMANENT;
-    $file = file_save($files[0]);
-    $fid = $file->fid;
-
-    // The default view mode should be selected by default.
-    $this->drupalGet('media/' . $fid . '/format-form');
-    $this->assertOptionSelected('edit-format', 'default');
-
-    $edit = array(
-      'media_wysiwyg_view_mode[media_wysiwyg_view_mode_image_wysiwyg_restricted_view_modes_status]' => TRUE,
-      'media_wysiwyg_view_mode[media_wysiwyg_view_mode_image_wysiwyg_restricted_view_modes][default]' => TRUE,
-    );
-    $this->drupalPost('admin/structure/file-types/manage/image/edit', $edit, 'Save');
-
-    // The teaser view mode should now be selected by default.
-    $this->drupalGet('media/' . $fid . '/format-form');
-    $this->assertOptionSelected('edit-format', 'teaser');
-  }
-}
diff --git a/drupal7/sites/all/modules/media/modules/mediafield/mediafield.info b/drupal7/sites/all/modules/media/modules/mediafield/mediafield.info
index f78d47ef..c67ecf28 100644
--- a/drupal7/sites/all/modules/media/modules/mediafield/mediafield.info
+++ b/drupal7/sites/all/modules/media/modules/mediafield/mediafield.info
@@ -4,9 +4,9 @@ package = Media
 core = 7.x
 dependencies[] = media
 
-; Information added by Drupal.org packaging script on 2016-11-15
-version = "7.x-2.0-beta7"
+; Information added by Drupal.org packaging script on 2016-11-20
+version = "7.x-2.0-beta9"
 core = "7.x"
 project = "media"
-datestamp = "1479212995"
+datestamp = "1479647342"
 
diff --git a/drupal7/sites/all/modules/media/tests/media_module_test.info b/drupal7/sites/all/modules/media/tests/media_module_test.info
index f17843c6..18e88aca 100644
--- a/drupal7/sites/all/modules/media/tests/media_module_test.info
+++ b/drupal7/sites/all/modules/media/tests/media_module_test.info
@@ -6,9 +6,9 @@ hidden = TRUE
 
 files[] = includes/MediaModuleTest.inc
 
-; Information added by Drupal.org packaging script on 2016-11-15
-version = "7.x-2.0-beta7"
+; Information added by Drupal.org packaging script on 2016-11-20
+version = "7.x-2.0-beta9"
 core = "7.x"
 project = "media"
-datestamp = "1479212995"
+datestamp = "1479647342"
 
