From 395002eca4a04b9adb27d0e1776c9bd658414a90 Mon Sep 17 00:00:00 2001 From: Darryl Norris Date: Thu, 5 Mar 2015 02:03:52 -0800 Subject: [PATCH] Experimental D8 export mobile detect module --- mobile_detect.drush.inc | 6 +-- mobile_detect.info | 6 --- mobile_detect.info.yml | 5 ++ mobile_detect.install | 2 +- mobile_detect.module | 77 +++++----------------------- mobile_detect.permissions.yml | 3 ++ src/Plugin/Block/MobileDetectFullDebug.php | 34 ++++++++++++ src/Plugin/Block/MobileDetectSimpleDebug.php | 34 ++++++++++++ 8 files changed, 92 insertions(+), 75 deletions(-) delete mode 100644 mobile_detect.info create mode 100644 mobile_detect.info.yml create mode 100644 mobile_detect.permissions.yml create mode 100644 src/Plugin/Block/MobileDetectFullDebug.php create mode 100644 src/Plugin/Block/MobileDetectSimpleDebug.php diff --git a/mobile_detect.drush.inc b/mobile_detect.drush.inc index d64e3ee..1f62fde 100644 --- a/mobile_detect.drush.inc +++ b/mobile_detect.drush.inc @@ -38,14 +38,14 @@ function mobile_detect_drush_help($section) { * Callback for mobile-detect */ function _mobile_detect_drush_download() { - if (module_exists('libraries')) { + if (\Drupal::moduleHandler()->moduleExists('libraries')) { /* TODO: a site may not be using this path for libraries... not sure what API call to use to * determine the basepath for all libraries... */ - $path = 'sites/all/libraries/Mobile_Detect'; + $path = 'libraries/Mobile_Detect'; } else { - $path = 'sites/all/libraries/Mobile_Detect'; + $path = 'libraries/Mobile_Detect'; } if (!is_dir($path)) { diff --git a/mobile_detect.info b/mobile_detect.info deleted file mode 100644 index a33d90c..0000000 --- a/mobile_detect.info +++ /dev/null @@ -1,6 +0,0 @@ -name = Mobile Detect -description = Lightweight mobile detection based on Mobile_Detect.php -core = 7.x -package = Mobile Detect - -files[] = mobile_detect.drush.inc diff --git a/mobile_detect.info.yml b/mobile_detect.info.yml new file mode 100644 index 0000000..2ab8a42 --- /dev/null +++ b/mobile_detect.info.yml @@ -0,0 +1,5 @@ +name: 'Mobile Detect' +description: 'Lightweight mobile detection based on Mobile_Detect.php' +core: 8.x +package: 'Mobile Detect' +type: module diff --git a/mobile_detect.install b/mobile_detect.install index fcc5083..a42c812 100644 --- a/mobile_detect.install +++ b/mobile_detect.install @@ -15,7 +15,7 @@ function mobile_detect_requirements($phase) { return $items; } - $t = get_t(); + $t = 't'; $status = array('title' => $t('Mobile Detect')); diff --git a/mobile_detect.module b/mobile_detect.module index 5f5dd6e..48bd0e9 100644 --- a/mobile_detect.module +++ b/mobile_detect.module @@ -18,8 +18,8 @@ function mobile_detect_help($path, $arg) { function _mobile_detect_get_readme() { $readme = file_get_contents(dirname(__FILE__) . '/README.txt'); - if (module_exists('markdown')) { - $filters = module_invoke('markdown', 'filter_info'); + if (\Drupal::moduleHandler()->moduleExists('markdown')) { + $filters = \Drupal::moduleHandler()->invoke('markdown', 'filter_info'); $info = $filters['filter_markdown']; if (function_exists($info['process callback'])) { @@ -67,12 +67,11 @@ function mobile_detect_get_object() { $detect = new Mobile_Detect(); } catch (Exception $e) { $detect = NULL; - watchdog('mobile_detect', 'Could not instantiate Mobile_Detect(): %message', - array('%message' => $e->getMessage()), WATCHDOG_ALERT); + \Drupal::logger('mobile_detect')->alert('Could not instantiate Mobile_Detect(): %message', array('%message' => $e->getMessage())); } } else { $detect = NULL; - watchdog('mobile_detect', 'Mobile_Detect() class does not exist', array(), WATCHDOG_ALERT); + \Drupal::logger('mobile_detect')->alert('Mobile_Detect() class does not exist', array()); } } @@ -100,8 +99,7 @@ function mobile_detect_check_type($type) { $name = preg_replace('/^is/', '', $type); if ($name != 'Mobile' && $name != 'Tablet' && !in_array($name, $rules)) { - watchdog('mobile_detect', 'Illegal access rule: %type', - array('%type' => $type), WATCHDOG_ERROR); + \Drupal::logger('mobile_detect')->error('Illegal access rule: %type', array('%type' => $type)); return FALSE; } @@ -131,63 +129,6 @@ function _mobile_detect_get_library_path() { return $library_path; } -/** - * Implements hook_permission(). - */ -function mobile_detect_permission() { - return array( - 'view mobile detect debug' => array( - 'title' => t('View Mobile Detect Debug'), - 'description' => t('Allows users to view the Mobile Detect debug blocks, etc.'), - ), - ); -} - -/** - * Implements function hook_block_info(). - */ -function mobile_detect_block_info() { - $blocks = array(); - - $blocks['mobile_detect_simple_debug'] = array( - 'info' => t('Mobile Detect Simple Debug'), - 'cache' => DRUPAL_NO_CACHE, - ); - - $blocks['mobile_detect_full_debug'] = array( - 'info' => t('Mobile Detect Full Debug'), - 'cache' => DRUPAL_NO_CACHE, - ); - - return $blocks; -} - -/** - * Implements function hook_block_view(). - */ -function mobile_detect_block_view ($delta) { - $block = array(); - - if (user_access('view mobile detect debug')) { - switch ($delta) { - case 'mobile_detect_simple_debug': - $block['subject'] = t('Mobile Detect: Simple debug'); - $block['content'] = array( - '#markup' => _mobile_detect_simple_debug(), - ); - break; - - case 'mobile_detect_full_debug': - $block['subject'] = t('Mobile Detect: Full debug'); - $block['content'] = array( - '#markup' => _mobile_detect_full_debug(), - ); - break; - } - } - - return $block; -} /** * Content generator for hook_block_view('mobile_detect_simple_debug') @@ -208,6 +149,9 @@ function _mobile_detect_simple_debug() { $output[] = '
' . t('isTablet') . '
'; $output[] = '
' . ($detect->isTablet() ? $true : $false) . '
'; + $output[] = '
' . t('Request Time') . '
'; + $output[] = '
' . REQUEST_TIME . '
'; + $output[] = ''; return join('', $output); @@ -238,7 +182,10 @@ function _mobile_detect_full_debug() { $output[] = '
' . t('is@name', array('@name' => $name)) . '
'; $output[] = '
' . ($detect->{$predicate}() ? $true : $false) . '
'; } - + + $output[] = '
' . t('Request Time') . '
'; + $output[] = '
' . REQUEST_TIME . '
'; + $output[] = ''; return join('', $output); diff --git a/mobile_detect.permissions.yml b/mobile_detect.permissions.yml new file mode 100644 index 0000000..d6662dd --- /dev/null +++ b/mobile_detect.permissions.yml @@ -0,0 +1,3 @@ +'view mobile detect debug': + title: 'View Mobile Detect Debug' + description: 'Allows users to view the Mobile Detect debug blocks, etc.' diff --git a/src/Plugin/Block/MobileDetectFullDebug.php b/src/Plugin/Block/MobileDetectFullDebug.php new file mode 100644 index 0000000..2c07848 --- /dev/null +++ b/src/Plugin/Block/MobileDetectFullDebug.php @@ -0,0 +1,34 @@ +