Skip to content

Latest commit

 

History

History
59 lines (46 loc) · 1.12 KB

README.md

File metadata and controls

59 lines (46 loc) · 1.12 KB

detect_mobile

drupal 8 module for detect mobile devices.

This is a lightweight mobile detection based on the Mobile_Detect.php library.

PHP examples

Check type device

$mobileDetector = \Drupal::service('krs.mobile_detect');
$mobileDetector->isMobile();
$mobileDetector->isTablet()

Check phone

is[iPhone|HTC|Nexus|Dell|Motorola|Samsung|Sony|Asus|Palm|Vertu|GenericPhone]

$mobileDetector->isIphone();
$mobileDetector->isHTC();
etc.

Check tablet

is[BlackBerryTablet|iPad|Kindle|SamsungTablet|HTCtablet|MotorolaTablet|AsusTablet|NookTablet|AcerTablet| YarvikTablet|GenericTablet]

$mobileDetector->isIpad();
$mobileDetector->isMotorolaTablet();
etc.

Check mobile OS

is[AndroidOS|BlackBerryOS|PalmOS|SymbianOS|WindowsMobileOS|iOS|badaOS]

$mobileDetector->isAndroidOS();
$mobileDetector->isIOS();

Twig Helper

{% if is_mobile() %}
{% if is_tablet() %}
{% if is_device('iphone') %} 
{% if is_ios() %}
{% if is_android_os() %}

TODO

  • redirect to mobile and tablet
  • Write tests