Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat(core): add exmaple for new hook (pre/post_item_accordion_section) #62

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,9 @@ function plugin_init_example() {
$PLUGIN_HOOKS[Hooks::PRE_ITEM_FORM]['example'] = [ItemForm::class, 'preItemForm'];
$PLUGIN_HOOKS[Hooks::POST_ITEM_FORM]['example'] = [ItemForm::class, 'postItemForm'];

$PLUGIN_HOOKS[Hooks::PRE_ITIL_INFO_SECTION]['example'] = [ItemForm::class, 'preSection'];
$PLUGIN_HOOKS[Hooks::POST_ITIL_INFO_SECTION]['example'] = [ItemForm::class, 'postSection'];

// Add new actions to timeline
$PLUGIN_HOOKS[Hooks::TIMELINE_ACTIONS]['example'] = [
ItemForm::class, 'timelineActions'
Expand Down
68 changes: 68 additions & 0 deletions src/ItemForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
*/

namespace GlpiPlugin\Example;

use Glpi\Application\View\TemplateRenderer;
use Html;
use Ticket;

Expand All @@ -39,6 +41,72 @@
* */
class ItemForm {


/**
* Display contents at the begining of ITILObject section (right panel).
*
* @param array $params Array with "item" and "options" keys
*
* @return void
*/
static public function preSection($params) {
$item = $params['item'];
$options = $params['options'];

echo TemplateRenderer::getInstance()->renderFromStringTemplate(<<<TWIG
<section class="accordion-item" aria-label="a label">
<h2 class="accordion-header" id="example-heading" title="example-heading-id" data-bs-toggle="tooltip">
<button class="accordion-button" type="button" data-bs-toggle="collapse" data-bs-target="#example-pre-content" aria-expanded="true" aria-controls="example-pre-content">
<i class="ti ti-world me-1"></i>
<span class="item-title">
Example pre section
</span>
</button>
</h2>
<div id="example-pre-content" class="accordion-collapse collapse" aria-labelledby="example-pre-content-heading">
<div class="accordion-body">
Example pre section
</div>
</div>
</section>
TWIG, []);

}

/**
* Display contents at the end of ITILObject section (right panel).
*
* @param array $params Array with "item" and "options" keys
*
* @return void
*/
static public function postSection($params) {
$item = $params['item'];
$options = $params['options'];

echo TemplateRenderer::getInstance()->renderFromStringTemplate(<<<TWIG
<section class="accordion-item" aria-label="a label">
<h2 class="accordion-header" id="example-heading" title="example-heading-id" data-bs-toggle="tooltip">
<button class="accordion-button" type="button" data-bs-toggle="collapse" data-bs-target="#example-post-content" aria-expanded="true" aria-controls="example-post-content">
<i class="ti ti-world me-1"></i>
<span class="item-title">
Example post section
</span>
</button>
</h2>
<div id="example-post-content" class="accordion-collapse collapse" aria-labelledby="example-post-content-heading">
<div class="accordion-body">
Example post section
</div>
</div>
</section>
TWIG, []);
}





/**
* Display contents at the begining of item forms.
*
Expand Down