Mobile Themes and tablets

Permalink
I saw some older discussions about being able to exclude tablets from the mobile theme when it is enabled. I agree with what others have said before, it would be nice to have an easy dashboard way to do that. With responsive themes the tablets really do not need a separate mobile theme, but there are times when having a separate theme for the xs devices would make sense.

I have one of those times right now with 5.7. Does anyone know how I can override the mobile detection so only xs devices like phones are served the mobile theme and tablets get the regular theme?

thanks

pvernaglia
 
MrKDilkington replied on at Permalink Best Answer Reply
MrKDilkington
Hi pvernaglia,

http://mobiledetect.net/
// Exclude tablets.
if( $detect->isMobile() && !$detect->isTablet() ){
}

I wonder if you could override concrete/src/Routing/DispatcherRouteCallback.php.
- instead of checking: if ($md->isMobile())
- you could check for: if ($md->isMobile() && !$md->isTablet())

Current:
// Mobile theme
if (Config::get('concrete.misc.mobile_theme_id') > 0) {
    $md = new \Mobile_Detect();
    if ($md->isMobile()) {
        $mobileTheme = Theme::getByID(Config::get('concrete.misc.mobile_theme_id'));
        if($mobileTheme instanceof Theme) {
            $view->setViewTheme($mobileTheme);
        }
    }
}

https://github.com/concrete5/concrete5-5.7.0/blob/88f8d6749c30c4c073...

Override:
// Mobile theme
if (Config::get('concrete.misc.mobile_theme_id') > 0) {
    $md = new \Mobile_Detect();
    if ($md->isMobile() && !$md->isTablet()) {
        $mobileTheme = Theme::getByID(Config::get('concrete.misc.mobile_theme_id'));
        if ($mobileTheme instanceof Theme) {
            $view->setViewTheme($mobileTheme);
        }
    }
}
pvernaglia replied on at Permalink Reply
pvernaglia
HI, Yes, editing concrete/src/Routing/DispatcherRouteCallback.php with the code you suggested does exclude tablets from the mobile theme, which is exactly what I need to do.

However tying to override by copying it to applications/src/Routing/DispatcherRouteCallback.php does not work. So there must be some trick to overriding the core src code???
MrKDilkington replied on at Permalink Reply
MrKDilkington
I asked someone on IRC about this and they think you might not be able to override that class.

Unless someone else comes up with an alternative, I would consider making a GitHub issue for it.
Shotster replied on at Permalink Reply
Shotster
> I asked someone on IRC about this and they think you might not be able to override that class.
> Unless someone else comes up with an alternative, I would consider making a GitHub issue for it.

As far as I can tell, the only reason that class can't be overridden is because it's not being "properly" instantiated via the IoC container - i.e. through the Core::make() method. Overriding or extending that class SHOULD be as simple as adding the following to your application/bootstrap/app.php file...

Core::bind('\Concrete\Core\Routing\DispatcherRouteCallback', function($app, $params) {
   return new \Application\Src\Routing\DispatcherRouteCallback($params[0]);
});

...and then "mirroring" the core file in your application directory to either override the class or extend it and override just the method(s) of interest. The namespace gymnastics described in the HowTo should be unnecessary.

I've created a PR here...

https://github.com/concrete5/concrete5/pull/2591...

-Steve
MrKDilkington replied on at Permalink Reply
MrKDilkington
Thank you for the information, Steve.

I have bookmarked it.
MrKDilkington replied on at Permalink Reply
MrKDilkington
@pvernaglia

If you still need this file overridden, there is a new How-To by Mainio that might have the solution.
https://www.concrete5.org/documentation/how-tos/developers/override-...