From c07be3395f6a67928403221a0f8dbb4f2d82c836 Mon Sep 17 00:00:00 2001
From: William Hearn <sylus1984@gmail.com>
Date: Tue, 20 Sep 2016 10:33:50 -0400
Subject: [PATCH] Issue #2529032 by inders, markcarver: Upgrade To Drupal 8

---
 icon.links.menu.yml                 |  4 ++--
 icon.module                         | 32 ++++++++++++++++++--------------
 icon.routing.yml                    |  4 ++--
 includes/admin.inc                  |  8 ++++----
 includes/cache.inc                  |  6 +++---
 includes/utilities.inc              | 10 +++++-----
 src/Form/IconBundleOverviewForm.php | 16 ++++++++--------
 7 files changed, 42 insertions(+), 38 deletions(-)

diff --git icon.links.menu.yml icon.links.menu.yml
index 9effc32..80b3c7f 100644
--- icon.links.menu.yml
+++ icon.links.menu.yml
@@ -1,5 +1,5 @@
-book.admin:
+icon.admin:
   title: Icons
   description: 'Overview of all available icons.'
   parent: system.admin_config_media
-  route_name: system.icon
+  route_name: icon.overview
diff --git icon.module icon.module
index e1987c3..bfd6efc 100644
--- icon.module
+++ icon.module
@@ -1,9 +1,11 @@
 <?php
+
 /**
  * @file
  * icon.module
  * Provides icon integration with menu items.
  */
+
 use Drupal\Core\Cache\Cache;
 use Drupal\Core\Extension\Extension;
 use Drupal\Core\Extension\ExtensionDiscovery;
@@ -109,7 +111,7 @@ function icon_menu() {
     'file' => 'admin.inc',
     'file path' => $module_path . '/includes',
   );
-  $items[ICON_ADMIN_PATH . '/bundle/%con_bundle/icons'] = array(
+  $items[ICON_ADMIN_PATH . '/bundle/%icon_bundle/icons'] = array(
     'type' => MENU_DEFAULT_LOCAL_TASK,
     'title' => 'Icons',
     'description' => 'Provide an overview of all available icon bundles.',
@@ -277,7 +279,7 @@ function &icon_render_hooks($hook = NULL, $reset = FALSE) {
  *   The machine name of the bundle.
  */
 function icon_bundle_defaults(&$bundle = array(), $name = '') {
-  $bundle_extra = array(
+  $bundle += array(
     'icons' => array(),
     'name' => $name,
     'provider' => '',
@@ -287,7 +289,6 @@ function icon_bundle_defaults(&$bundle = array(), $name = '') {
     'version' => '',
     '#attached' => array(),
   );
-  $bundle = array_merge($bundle_extra, $bundle);
   return $bundle;
 }
 
@@ -307,7 +308,7 @@ function icon_bundle_defaults(&$bundle = array(), $name = '') {
 function icon_bundles($name = NULL, $reset = FALSE) {
   $bundles = & drupal_static(__FUNCTION__);
   if (!isset($bundles) || $reset) {
-    if (!$reset && ($cache = \Drupal::cache()->get('icon_render_hooks')) && !empty($cache->data)) {      
+    if (!$reset && ($cache = \Drupal::cache()->get('icon_bundles')) && !empty($cache->data)) {
       $bundles = $cache->data;
     }
     else {
@@ -539,16 +540,16 @@ function icon_bundle_save(array $bundle = array()) {
   if (!empty($diff)) {
     $record['bundle'] = $bundle;
   }
-  // Only write to the database if necessary.
+  // Only write to the database if the record exists and needs to be saved.
   if (isset($record['status']) || isset($record['bundle'])) {
-     $status = \Drupal::database()->merge('icon_bundle')
-       ->key(array('name' => $record['name'],))
-       ->fields(array('bundle' => $record['bundle'], 'status' => $record['status']))
-       ->execute();
-     if($status) {
-       icon_clear_all_caches();
-       return $status;
-     }
+    $status = \Drupal::database()->merge('icon_bundle')
+      ->key(array('name' => $record['name']))
+      ->fields(array('bundle' => $record['bundle'], 'status' => $record['status']))
+      ->execute();
+    if ($status) {
+      icon_clear_all_caches();
+      return $status;
+    }
   }
   return FALSE;
 }
@@ -560,6 +561,9 @@ function icon_bundle_save(array $bundle = array()) {
  *   An associative array of provider information, passed by reference.
  * @param string $name
  *   The machine name of the provider.
+ *
+ * @return array|false
+ *   An associative array containing information about a provider
  */
 function icon_provider_defaults(&$provider = array(), $name = '') {
   $provider += array(
@@ -587,7 +591,7 @@ function icon_provider_defaults(&$provider = array(), $name = '') {
 function icon_providers($name = NULL, $reset = FALSE) {
   $providers = & drupal_static(__FUNCTION__);
   if (!isset($providers) || $reset) {
-    if (!$reset && ($cache = \Drupal::cache()->get('icon_providers')) && !empty($cache->data)) {      
+    if (!$reset && ($cache = \Drupal::cache()->get('icon_providers')) && !empty($cache->data)) {
       $providers = $cache->data;
     }
     else {
diff --git icon.routing.yml icon.routing.yml
index 0efa772..1ba9542 100644
--- icon.routing.yml
+++ icon.routing.yml
@@ -1,7 +1,7 @@
-system.icon:
+icon.overview:
   path: '/admin/config/media/icon'
   defaults:
     _form: 'Drupal\icon\Form\IconBundleOverviewForm'
     _title: 'Icons'
   requirements:
-    _permission: 'administer icons'
\ No newline at end of file
+    _permission: 'administer icons'
diff --git includes/admin.inc includes/admin.inc
index a25878e..178a1a6 100644
--- includes/admin.inc
+++ includes/admin.inc
@@ -54,8 +54,8 @@ function icon_bundle_overview_form($form, &$form_state) {
     '#title' => t('View Path'),
     '#field_prefix' => base_path(),
     '#input_group' => TRUE,
-    '#description' => t('If provided, users with the "view icons" permission will be able to view enabled icons at this URL (defaults to: <code>!path</code>. Change this url if it conflicts with other paths on your site. Leave empty to disable.', array(
-      '!path' => base_path() . 'icons',
+    '#description' => t('If provided, users with the "view icons" permission will be able to view enabled icons at this URL (defaults to: <code>:path</code>. Change this url if it conflicts with other paths on your site. Leave empty to disable.', array(
+      ':path' => base_path() . 'icons',
     )),
     '#default_value' => $view_path,
   );
@@ -63,8 +63,8 @@ function icon_bundle_overview_form($form, &$form_state) {
   $apache_show_warning = ($view_path === 'icons' && strpos(drupal_strtolower($_SERVER['SERVER_SOFTWARE']), 'apache') !== FALSE);
   $apache_suppress_warning = variable_get('icon_api_apache_suppress_warning', FALSE);
   if ($apache_show_warning && !$apache_suppress_warning) {
-    drupal_set_message(t('<strong>WARNING:</strong> Apache installations are typically configured with a server level alias that redirects "/icons" to an internal directory on the server. It is highly recommended that this be removed from the configuration file for the view path to work properly. If this modification has been made to the server, you may surpress this messages in the global settings below. The only alternative is to change the view path in the global settings below. See: <a href="!link">!link</a>.', array(
-      '!link' => 'https://drupal.org/node/2198427',
+    drupal_set_message(t('<strong>WARNING:</strong> Apache installations are typically configured with a server level alias that redirects "/icons" to an internal directory on the server. It is highly recommended that this be removed from the configuration file for the view path to work properly. If this modification has been made to the server, you may surpress this messages in the global settings below. The only alternative is to change the view path in the global settings below. See: <a href=":link">:link</a>.', array(
+      ':link' => 'https://drupal.org/node/2198427',
     )), 'warning', FALSE);
   }
   // Provide toggle for suppressing warning message.
diff --git includes/cache.inc includes/cache.inc
index 1a7bb56..75f1873 100644
--- includes/cache.inc
+++ includes/cache.inc
@@ -6,7 +6,7 @@
  */
 
 use Drupal\Core\Cache\Cache;
-use Drupal\Component\Utility\String;
+use Drupal\Component\Utility\SafeMarkup;
 use Drupal\Core\Database\Query\AlterableInterface;
 use Drupal\Core\Form\FormStateInterface;
 use Drupal\Core\Render\Element;
@@ -31,8 +31,8 @@ function icon_flush_caches() {
  * Clears all caches used by the icon module.
  */
 function icon_clear_all_caches() {
-  \Drupal::cache()->deleteAll();
-  
+  \Drupal::cache()->deleteAll('icon_');
+
   icon_reset_static_cache();
   // Rebuild icon data.
   icon_render_hooks();
diff --git includes/utilities.inc includes/utilities.inc
index 428cf1c..393991e 100644
--- includes/utilities.inc
+++ includes/utilities.inc
@@ -271,14 +271,14 @@ function icon_enabled_themes() {
   if (!isset($themes)) {
     $themes = array();
     foreach (\Drupal::service('theme_handler')->listInfo() as $theme) {
-      if (!$theme->status || in_array($theme->name, $themes)) {
+      if (!$theme->status || in_array($theme->getName(), $themes)) {
         continue;
       }
-      $themes[] = $theme->name;
+      $themes[] = $theme->getName();
       // Merge in the base themes if this is a sub-theme.
-      if (isset($theme->base_themes)) {
+      if (isset($theme->sub_themes)) {
         // Only add the theme if it's not already in the list.
-        foreach (array_keys($theme->base_themes) as $name) {
+        foreach (array_keys($theme->sub_themes) as $name) {
           if (!in_array($name, $themes)) {
             $themes[] = $name;
           }
@@ -363,7 +363,7 @@ function icon_find_theme_include($theme) {
     $themes[$theme] = FALSE;
     if (!isset($includes)) {
       $includes = array();
-      $listing = new ExtensionDiscovery();
+      $listing = new ExtensionDiscovery(\Drupal::root());
       $available_themes = $listing->scan('themes');
       foreach ($listing->scan('themes') as $theme) {
         if (file_exists($filepath = $theme->getPath() . '/icons.inc')) {
diff --git src/Form/IconBundleOverviewForm.php src/Form/IconBundleOverviewForm.php
index 9d40396..c5c9a00 100644
--- src/Form/IconBundleOverviewForm.php
+++ src/Form/IconBundleOverviewForm.php
@@ -25,7 +25,7 @@ class IconBundleOverviewForm extends ConfigFormBase {
    * {@inheritdoc}
    */
   public function buildForm(array $form, FormStateInterface $form_state) {
-    $config = $this->config('system.icon');
+    $config = $this->config('icon.overview');
     // Attach UI fonts for Icon API.
 //    $module_path = drupal_get_path('module', 'icon');
 //    $form['#attached'] = array(
@@ -72,8 +72,8 @@ class IconBundleOverviewForm extends ConfigFormBase {
         '#title' => t('View Path'),
         '#field_prefix' => base_path(),
         '#input_group' => TRUE,
-        '#description' => t('If provided, users with the "view icons" permission will be able to view enabled icons at this URL (defaults to: <code>!path</code>. Change this url if it conflicts with other paths on your site. Leave empty to disable.', array(
-            '!path' => base_path() . 'icons',
+        '#description' => t('If provided, users with the "view icons" permission will be able to view enabled icons at this URL (defaults to: <code>:path</code>. Change this url if it conflicts with other paths on your site. Leave empty to disable.', array(
+            ':path' => base_path() . 'icons',
         )),
         '#default_value' => $view_path,
     );
@@ -81,8 +81,8 @@ class IconBundleOverviewForm extends ConfigFormBase {
     $apache_show_warning = ($view_path === 'icons' && strpos(\Drupal\Component\Utility\Unicode::strtolower($_SERVER['SERVER_SOFTWARE']), 'apache') !== FALSE);
     $apache_suppress_warning = \Drupal::config('icon.settings')->get('icon_api_apache_suppress_warning');
     if ($apache_show_warning && !$apache_suppress_warning) {
-      drupal_set_message(t('<strong>WARNING:</strong> Apache installations are typically configured with a server level alias that redirects "/icons" to an internal directory on the server. It is highly recommended that this be removed from the configuration file for the view path to work properly. If this modification has been made to the server, you may surpress this messages in the global settings below. The only alternative is to change the view path in the global settings below. See: <a href="!link">!link</a>.', array(
-          '!link' => 'https://drupal.org/node/2198427',
+      drupal_set_message(t('<strong>WARNING:</strong> Apache installations are typically configured with a server level alias that redirects "/icons" to an internal directory on the server. It is highly recommended that this be removed from the configuration file for the view path to work properly. If this modification has been made to the server, you may surpress this messages in the global settings below. The only alternative is to change the view path in the global settings below. See: <a href=":link">:link</a>.', array(
+          ':link' => 'https://drupal.org/node/2198427',
               )), 'warning', FALSE);
     }
     // Provide toggle for suppressing warning message.
@@ -112,13 +112,13 @@ class IconBundleOverviewForm extends ConfigFormBase {
     if (!\Drupal::currentUser()->hasPermission('administer icons')) {
       form_set_error('', t('You are not authorized to submit this form.'));
     }
-    
+
     $view_path_alias = $form_state->getValue('icon_api_view_path_alias');
     // @FIXME
     // menu_get_item() has been removed. To retrieve route information, use the
     // RouteMatch object, which you can retrieve by calling \Drupal::routeMatch().
-    // 
-    // 
+    //
+    //
     // @see https://www.drupal.org/node/2203305
     // if ($form['global']['icon_api_view_path_alias']['#default_value'] !== $form_state['values']['icon_api_view_path_alias'] && menu_get_item($view_path_alias)) {
     //     form_set_error('icon_api_view_path_alias', t('The view path alias provided, "%url", is already in use. Please enter a different path.', array(
-- 
2.5.4 (Apple Git-61)

