Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| d2558c5f55 | |||
| 97ded0eb08 | |||
| 3afcc69531 | |||
| 75c31f0506 |
@@ -2,7 +2,8 @@
|
||||
"bundle": {
|
||||
"js/admin": {
|
||||
"scripts": [
|
||||
"uf-tweaks/js/handlebars-helpers.js"
|
||||
"uf-tweaks/js/handlebars-helpers.js",
|
||||
"uf-tweaks/js/modal-error-handler.js"
|
||||
],
|
||||
"options": {
|
||||
"sprinkle": {
|
||||
|
||||
16
assets/uf-tweaks/js/modal-error-handler.js
Normal file
16
assets/uf-tweaks/js/modal-error-handler.js
Normal file
@@ -0,0 +1,16 @@
|
||||
|
||||
/**
|
||||
* Default handling of UF modal error
|
||||
*
|
||||
* This script depends on uf-modal.js
|
||||
*
|
||||
* Target page: *
|
||||
*/
|
||||
|
||||
$(document).ready(function() {
|
||||
const handleModalError = function() {
|
||||
$(this).ufModal('destroy');
|
||||
$('body').on('renderError.ufModal', handleModalError);
|
||||
}
|
||||
$('body').on('renderError.ufModal', handleModalError);
|
||||
});
|
||||
@@ -6,5 +6,8 @@
|
||||
"psr-4": {
|
||||
"UserFrosting\\Sprinkle\\UFTweaks\\": "src/"
|
||||
}
|
||||
},
|
||||
"require": {
|
||||
"mobiledetect/mobiledetectlib": "^3.74"
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,7 @@
|
||||
|
||||
namespace UserFrosting\Sprinkle\UFTweaks\ServicesProvider;
|
||||
|
||||
use Illuminate\Database\Capsule\Manager as Capsule;
|
||||
use Monolog\Formatter\LineFormatter;
|
||||
use Monolog\Handler\StreamHandler;
|
||||
use Monolog\Logger;
|
||||
@@ -17,6 +18,7 @@ use Psr\Http\Message\ResponseInterface as Response;
|
||||
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||
use UserFrosting\Sprinkle\Core\Log\MixedFormatter;
|
||||
use UserFrosting\Sprinkle\UFTweaks\Twig\HasRoleExtension;
|
||||
use UserFrosting\Sprinkle\UFTweaks\Twig\MobileDetectExtension;
|
||||
|
||||
|
||||
/**
|
||||
@@ -150,6 +152,25 @@ class ServicesProvider
|
||||
}
|
||||
);
|
||||
|
||||
/*
|
||||
* Check if the specified user (by user_id) has a particular permission.
|
||||
*
|
||||
* @param int $user_id the id of the user.
|
||||
* @param int $permission_slug slug of the permission to check.
|
||||
* @return bool true if the user has the permission, false otherwise.
|
||||
*/
|
||||
$authorizer->addCallback(
|
||||
'has_permission',
|
||||
function ($user_id, $permission_slug) {
|
||||
return Capsule::table('role_users')
|
||||
->join('permission_roles', 'role_users.role_id', '=', 'permission_roles.role_id')
|
||||
->join('permissions', 'permission_roles.permission_id', '=', 'permissions.id')
|
||||
->where('user_id', $user_id)
|
||||
->where('slug', $permission_slug)
|
||||
->count() > 0;
|
||||
}
|
||||
);
|
||||
|
||||
return $authorizer;
|
||||
});
|
||||
|
||||
@@ -162,6 +183,7 @@ class ServicesProvider
|
||||
$twig = $view->getEnvironment();
|
||||
|
||||
$twig->addExtension(new HasRoleExtension($c));
|
||||
$twig->addExtension(new MobileDetectExtension($c));
|
||||
|
||||
return $view;
|
||||
});
|
||||
|
||||
60
src/Twig/MobileDetectExtension.php
Normal file
60
src/Twig/MobileDetectExtension.php
Normal file
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* AVSDev UF Tweaks (https://avsdev.uk)
|
||||
*
|
||||
* @link https://git.avsdev.uk/avsdev/sprinkle-uf-tweaks
|
||||
* @license https://git.avsdev.uk/avsdev/sprinkle-uf-tweaks/blob/master/LICENSE.md (LGPL-3.0 License)
|
||||
*/
|
||||
|
||||
namespace UserFrosting\Sprinkle\UFTweaks\Twig;
|
||||
|
||||
use Detection\MobileDetect;
|
||||
use Psr\Container\ContainerInterface;
|
||||
use Twig\Extension\AbstractExtension;
|
||||
use Twig\Extension\GlobalsInterface;
|
||||
use Twig\TwigFunction;
|
||||
|
||||
/**
|
||||
* Extends Twig functionality for mobile detection.
|
||||
*
|
||||
* @author Craig Williams (https://avsdev.uk)
|
||||
*/
|
||||
class MobileDetectExtension extends AbstractExtension implements GlobalsInterface
|
||||
{
|
||||
/**
|
||||
* @param ContainerInterface $services
|
||||
*/
|
||||
public function __construct(ContainerInterface $services)
|
||||
{
|
||||
}
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return 'avsdev/uf-tweaks-mobileDetect';
|
||||
}
|
||||
|
||||
public function getFunctions()
|
||||
{
|
||||
return [
|
||||
// Add Twig function for checking permissions during dynamic menu rendering
|
||||
new TwigFunction('isMobile', function () {
|
||||
$detect = new MobileDetect();
|
||||
return $detect->isMobile();
|
||||
}),
|
||||
new TwigFunction('isTablet', function () {
|
||||
$detect = new MobileDetect();
|
||||
return $detect->isTablet();
|
||||
}),
|
||||
new TwigFunction('isDesktop', function () {
|
||||
$detect = new MobileDetect();
|
||||
return !$detect->isTablet() && !$detect->isMobile();
|
||||
}),
|
||||
];
|
||||
}
|
||||
|
||||
public function getGlobals()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
{% if 'description' not in form.fields.hidden %}
|
||||
{% if 'slug' not in form.fields.hidden %}
|
||||
{% if col_width %}<div class="{{col_width}}">{% endif %}
|
||||
<div class="form-group">
|
||||
<label for="input-{{type}}-slug" class="control-label">{{field_name | default(translate('SLUG'))}}</label>
|
||||
@@ -15,4 +15,6 @@
|
||||
</div>
|
||||
</div>
|
||||
{% if col_width %}</div>{% endif %}
|
||||
{% else %}
|
||||
<input type="hidden" id="input-{{type}}-slug" name="slug" value="{{current_value}}">
|
||||
{% endif %}
|
||||
Reference in New Issue
Block a user