Skip to content

Commit 96b0919

Browse files
committed
twig
1 parent 216a76f commit 96b0919

5 files changed

Lines changed: 149 additions & 44 deletions

File tree

.twig_cs.dist.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use FriendsOfTwig\Twigcs;
6+
7+
$finder = Twigcs\Finder\TemplateFinder::create()
8+
->in(__DIR__ . '/templates')
9+
->name('*.html.twig')
10+
->ignoreVCSIgnored(true);
11+
12+
return Twigcs\Config\Config::create()
13+
->setFinder($finder)
14+
->setRuleSet(\Glpi\Tools\GlpiTwigRuleset::class)
15+
;

composer.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
},
55
"require-dev": {
66
"friendsofphp/php-cs-fixer": "^3.75",
7+
"friendsoftwig/twigcs": "^6.5",
78
"glpi-project/tools": "^0.7.5",
89
"php-parallel-lint/php-parallel-lint": "^1.4",
910
"phpstan/extension-installer": "^1.4",
@@ -22,5 +23,10 @@
2223
"allow-plugins": {
2324
"phpstan/extension-installer": true
2425
}
26+
},
27+
"autoload-dev": {
28+
"psr-4": {
29+
"Glpi\\Tools\\": "../../tools/src/"
30+
}
2531
}
2632
}

composer.lock

Lines changed: 56 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

inc/application.class.php

Lines changed: 8 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
* -------------------------------------------------------------------------
2929
*/
3030

31+
use Glpi\Application\View\TemplateRenderer;
3132
use GlpiPlugin\Oauthimap\MailCollectorFeature;
3233
use GlpiPlugin\Oauthimap\Provider\Azure;
3334
use GlpiPlugin\Oauthimap\Provider\Google;
@@ -287,53 +288,17 @@ public static function showFormExtra(int $id): void
287288

288289
$documentation_urls_json = json_encode(self::getProvidersDocumentationUrls());
289290

290-
// Display/hide additionnal params and update documentation link depending on selected provider
291-
$additionnal_params_js = <<<JAVASCRIPT
292-
(function($) {
293-
var documentation_urls = {$documentation_urls_json};
291+
$callback_url = self::getCallbackUrl();
294292

295-
var updateDocumentationLink = function () {
296-
var provider = $('#dropdown_provider{$rand}').val();
297-
298-
var url = documentation_urls.hasOwnProperty(provider)
299-
? documentation_urls[provider]
300-
: null;
301-
302-
$('.help-link').attr('href', url).toggle(url !== null);
303-
};
304-
305-
var onProviderChange = function () {
306-
var provider = $.escapeSelector($(this).val()); // escape selector as it contains slashes
307-
$('[data-provider="' + provider + '"]').closest('.form-field').show();
308-
$('[data-provider]:not([data-provider="' + provider + '"])').closest('.form-field').hide();
309-
310-
updateDocumentationLink();
311-
};
312-
313-
$('#dropdown_provider{$rand}').change(onProviderChange);
314-
onProviderChange.call($('#dropdown_provider{$rand}'));
315-
})(jQuery);
316-
JAVASCRIPT;
317-
318-
echo '<div class="form-field row col-12 col-sm-6 mb-2">';
319-
echo Html::scriptBlock($additionnal_params_js);
320-
echo '<label class="col-form-label col-xxl-5 text-xxl-end" for="_callback_url_' . $rand . '">';
321-
echo __('Callback url', 'oauthimap');
322-
echo ' <i class="fa fa-info pointer" title="' . __('copy it in the management console of provider', 'oauthimap') . '"></i>';
323-
echo '</label>';
324-
echo '<div class="col-xxl-7 field-container">';
325-
echo '<div class="input-group flex-grow-1 copy_to_clipboard_wrapper">';
326-
echo Html::input(
327-
'',
293+
echo TemplateRenderer::getInstance()->render(
294+
'@oauthimap/application_form_extra.html.twig',
328295
[
329-
'value' => self::getCallbackUrl(),
330-
'readonly' => 'readonly',
296+
'rand' => $rand,
297+
'callback_url' => $callback_url,
298+
'documentation_urls' => self::getProvidersDocumentationUrls(),
299+
'documentation_urls_json' => $documentation_urls_json,
331300
],
332301
);
333-
echo '<i class="input-group-text fa-lg pointer copy_to_clipboard_wrapper" role="button"></i>';
334-
echo '</div>';
335-
echo '</div>';
336-
echo '</div>';
337302
}
338303

339304
public function prepareInputForAdd($input)
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
{#
2+
# -------------------------------------------------------------------------
3+
# oauthimap plugin for GLPI
4+
# -------------------------------------------------------------------------
5+
#
6+
# LICENSE
7+
#
8+
# This file is part of oauthimap plugin.
9+
#
10+
# This plugin is free software: you can redistribute it and/or modify
11+
# it under the terms of the GNU General Public License as published by
12+
# the Free Software Foundation, either version 3 of the License, or
13+
# (at your option) any later version.
14+
#
15+
# This plugin is distributed in the hope that it will be useful,
16+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
17+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+
# GNU General Public License for more details.
19+
#
20+
# You should have received a copy of the GNU General Public License
21+
# along with this plugin. If not, see <https://www.gnu.org/licenses/>.
22+
# -------------------------------------------------------------------------
23+
# @copyright Copyright (C) 2020-2025 by Teclib'
24+
# @license GPLv3+ https://www.gnu.org/licenses/gpl-3.0.fr.html
25+
# @link https://services.glpi-network.com
26+
# -------------------------------------------------------------------------
27+
#}
28+
29+
{% import 'components/form/fields_macros.html.twig' as fields %}
30+
31+
{{ fields.textField(
32+
'callback_url',
33+
callback_url,
34+
__('Callback url', 'oauthimap'), {
35+
copyable: true
36+
}
37+
) }}
38+
39+
<script>
40+
(function($) {
41+
var documentation_urls = {{ documentation_urls_json|raw }};
42+
43+
var updateDocumentationLink = function () {
44+
var provider = $('#dropdown_provider{{ rand }}').val();
45+
46+
var url = documentation_urls.hasOwnProperty(provider)
47+
? documentation_urls[provider]
48+
: null;
49+
50+
$('.help-link').attr('href', url).toggle(url !== null);
51+
};
52+
53+
var onProviderChange = function () {
54+
var provider = $.escapeSelector($(this).val()); // escape selector as il contient des slashes
55+
$('[data-provider="' + provider + '"]').closest('.form-field').show();
56+
$('[data-provider]:not([data-provider="' + provider + '"])').closest('.form-field').hide();
57+
58+
updateDocumentationLink();
59+
};
60+
61+
$('#dropdown_provider{{ rand }}').change(onProviderChange);
62+
onProviderChange.call($('#dropdown_provider{{ rand }}'));
63+
})(jQuery);
64+
</script>

0 commit comments

Comments
 (0)