Skip to content

Commit

Permalink
New hook to add custom header tags (#17263)
Browse files Browse the repository at this point in the history
  • Loading branch information
keboeoris authored Jul 2, 2024
1 parent f68bdee commit 89ce453
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/Html.php
Original file line number Diff line number Diff line change
Expand Up @@ -1304,6 +1304,19 @@ public static function includeHeader(
}
$tpl_vars['css_files'][] = ['path' => 'css/palettes/' . $theme . '.scss'];

// Add specific meta tags for plugins
$custom_header_tags = [];
if (isset($PLUGIN_HOOKS[Hooks::ADD_HEADER_TAG]) && count($PLUGIN_HOOKS[Hooks::ADD_HEADER_TAG])) {
foreach ($PLUGIN_HOOKS[Hooks::ADD_HEADER_TAG] as $plugin => $plugin_header_tags) {
if (!Plugin::isPluginActive($plugin)) {
continue;
}
array_push($custom_header_tags, ...$plugin_header_tags);
}
}
$tpl_vars['custom_header_tags'] = $custom_header_tags;


$tpl_vars['js_files'][] = ['path' => 'public/lib/base.js'];
$tpl_vars['js_files'][] = ['path' => 'js/webkit_fix.js'];
$tpl_vars['js_files'][] = ['path' => 'js/common.js'];
Expand Down
2 changes: 2 additions & 0 deletions src/Plugin/Hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class Hooks
// File hooks
const ADD_CSS = 'add_css';
const ADD_JAVASCRIPT = 'add_javascript';
const ADD_HEADER_TAG = 'add_header_tag';

// Function hooks with no parameters
const CHANGE_ENTITY = 'change_entity';
Expand Down Expand Up @@ -185,6 +186,7 @@ public static function getFunctionalHooks(): array
self::UNDISCLOSED_CONFIG_VALUE,
self::UNLOCK_FIELDS,
self::VCARD_DATA,
self::ADD_HEADER_TAG
];
}

Expand Down
5 changes: 5 additions & 0 deletions templates/layout/parts/head.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@
{# prevent robots to index GLPI instances #}
<meta name="robots" content="noindex, nofollow" />

{# Custom header tags for plugins #}
{% for header_tag in custom_header_tags %}
<{{ header_tag.tag }} {% for key, value in header_tag.properties %}{{ key }}="{{ value }}" {% endfor %}/>
{% endfor %}

<meta property="glpi:csrf_token" content="{{ csrf_token(true) }}" />

{% for css_file in css_files %}
Expand Down

0 comments on commit 89ce453

Please sign in to comment.