Skip to content
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

### Added

- Add notification tags for the fields of the notified item: `##fields.<block>.<field>##` for the value, `##lang.fields.<block>.<field>##` for the label. A value is only sent to the recipients whose profile can read the block
- Add the fields of tickets, changes and problems, and of the assets linked to a ticket, to the variables of the followup, task and solution templates: `{{ ticket.fields.<block>.<field> }}`, `{{ asset.fields.<block>.<field> }}`

### Fixed

- Remove redundant variable initialization in the question type AJAX controller
Expand Down
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,21 @@ Fields options (mandatory / read only) can be overridden for some item statuses.

![Screenshot](./docs/screenshots/override_by_status.png)

Fields can be used in notification templates of the items having notifications (tickets, changes, problems, projects, etc.), they are listed in the "Tags" tab of the templates:

* `##fields.<block>.<field>##`: value of the field, as displayed in the form (dropdown label, Yes / No, date in the recipient format, etc.)
* `##lang.fields.<block>.<field>##`: label of the field, translated in the recipient language

`<block>` and `<field>` are the system names, they do not change when a label is renamed. A value is only sent to the recipients whose profile can read the block in the entity of the item; it is empty for a recipient without GLPI account.

The fields of tickets, changes and problems can also be used in followup, task and solution templates, as `{{ ticket.fields.<block>.<field> }}` (or `change.`, `problem.`), as well as the fields of the assets linked to a ticket:

```twig
{% for asset in ticket.assets %}{{ asset.name }}: {{ asset.fields.<block>.<field> }}{% endfor %}
```

They are listed in the documentation of the template variables, with the filter to use for multiple lines text (`nl2br`) and rich text (`raw`). As in the item form, a value is only rendered if the profile of the user applying the template can read the block. When the template is applied by a form (the ticket is created without right checks) or by the cron (followups and reminders of pending reasons, sent to the requester), every value is rendered: this allows a form submitted by a requester to add a private followup with technical data for the technicians.

## Download

Releases can be donwloaded on [GitHub](https://github.com/PluginsGLPI/fields/releases).
Expand Down
24 changes: 24 additions & 0 deletions hook.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
* -------------------------------------------------------------------------
*/

use Glpi\ContentTemplates\Parameters\ParametersTypes\AttributeParameter;

/**
* Plugin install process
*
Expand Down Expand Up @@ -362,3 +364,25 @@ function plugin_item_transfer_fields(array $options): void
$container->updateFieldsValues($data, $itemtype, true);
}
}

/**
* Fields variables listed in the documentation of the template variables
*
* @return AttributeParameter[]
*/
function plugin_fields_get_content_template_parameter(?string $node_name): array
{
return PluginFieldsNotificationTag::getTemplateParameters($node_name);
}

/**
* Fields values of the item on which a followup, task or solution template is used
*
* @param array{node_name: string, id: int} $params
*
* @return array{fields?: array<string, array<string, string>>}
*/
function plugin_fields_get_content_template_value(array $params): array
{
return PluginFieldsNotificationTag::getTemplateValues($params['node_name'], (int) $params['id']);
}
Loading