Skip to content

Commit 5a54ffe

Browse files
authored
Merge pull request #62 from stonebuzz/add_hook_section
Feat(core): add exmaple for new hook (pre/post_item_accordion_section)
2 parents 26cf7a4 + e0648cc commit 5a54ffe

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed

setup.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,9 @@ function plugin_init_example() {
260260
$PLUGIN_HOOKS[Hooks::PRE_ITEM_FORM]['example'] = [ItemForm::class, 'preItemForm'];
261261
$PLUGIN_HOOKS[Hooks::POST_ITEM_FORM]['example'] = [ItemForm::class, 'postItemForm'];
262262

263+
$PLUGIN_HOOKS[Hooks::PRE_ITIL_INFO_SECTION]['example'] = [ItemForm::class, 'preSection'];
264+
$PLUGIN_HOOKS[Hooks::POST_ITIL_INFO_SECTION]['example'] = [ItemForm::class, 'postSection'];
265+
263266
// Add new actions to timeline
264267
$PLUGIN_HOOKS[Hooks::TIMELINE_ACTIONS]['example'] = [
265268
ItemForm::class, 'timelineActions'

src/ItemForm.php

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
*/
3030

3131
namespace GlpiPlugin\Example;
32+
33+
use Glpi\Application\View\TemplateRenderer;
3234
use Html;
3335
use Ticket;
3436

@@ -39,6 +41,72 @@
3941
* */
4042
class ItemForm {
4143

44+
45+
/**
46+
* Display contents at the begining of ITILObject section (right panel).
47+
*
48+
* @param array $params Array with "item" and "options" keys
49+
*
50+
* @return void
51+
*/
52+
static public function preSection($params) {
53+
$item = $params['item'];
54+
$options = $params['options'];
55+
56+
echo TemplateRenderer::getInstance()->renderFromStringTemplate(<<<TWIG
57+
<section class="accordion-item" aria-label="a label">
58+
<h2 class="accordion-header" id="example-heading" title="example-heading-id" data-bs-toggle="tooltip">
59+
<button class="accordion-button" type="button" data-bs-toggle="collapse" data-bs-target="#example-pre-content" aria-expanded="true" aria-controls="example-pre-content">
60+
<i class="ti ti-world me-1"></i>
61+
<span class="item-title">
62+
Example pre section
63+
</span>
64+
</button>
65+
</h2>
66+
<div id="example-pre-content" class="accordion-collapse collapse" aria-labelledby="example-pre-content-heading">
67+
<div class="accordion-body">
68+
Example pre section
69+
</div>
70+
</div>
71+
</section>
72+
TWIG, []);
73+
74+
}
75+
76+
/**
77+
* Display contents at the end of ITILObject section (right panel).
78+
*
79+
* @param array $params Array with "item" and "options" keys
80+
*
81+
* @return void
82+
*/
83+
static public function postSection($params) {
84+
$item = $params['item'];
85+
$options = $params['options'];
86+
87+
echo TemplateRenderer::getInstance()->renderFromStringTemplate(<<<TWIG
88+
<section class="accordion-item" aria-label="a label">
89+
<h2 class="accordion-header" id="example-heading" title="example-heading-id" data-bs-toggle="tooltip">
90+
<button class="accordion-button" type="button" data-bs-toggle="collapse" data-bs-target="#example-post-content" aria-expanded="true" aria-controls="example-post-content">
91+
<i class="ti ti-world me-1"></i>
92+
<span class="item-title">
93+
Example post section
94+
</span>
95+
</button>
96+
</h2>
97+
<div id="example-post-content" class="accordion-collapse collapse" aria-labelledby="example-post-content-heading">
98+
<div class="accordion-body">
99+
Example post section
100+
</div>
101+
</div>
102+
</section>
103+
TWIG, []);
104+
}
105+
106+
107+
108+
109+
42110
/**
43111
* Display contents at the begining of item forms.
44112
*

0 commit comments

Comments
 (0)