Skip to content
Merged
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
7 changes: 5 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
dist/
vendor/
/dist/
/node_modules/
/vendor/
.gh_token
.phpunit.result.cache
tests/files/
*.min.*
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).


## [UNRELEASED]

### Added

- Implement `Field` question type for new GLPI forms

## [1.22.2] - 2025-10-24

### Fixed
Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include ../../PluginsMakefile.mk
22 changes: 22 additions & 0 deletions inc/field.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
use Glpi\Features\Clonable;
use Glpi\DBAL\QueryExpression;
use Glpi\Application\View\TemplateRenderer;
use Glpi\Form\Question;

class PluginFieldsField extends CommonDBChild
{
Expand Down Expand Up @@ -350,6 +351,27 @@ public function pre_deleteItem()
*/
global $DB;

// Check if the field is used in a form question
$question = new Question();
$found = $question->find([
'type' => PluginFieldsQuestionType::class,
$this->fields['id'] => new QueryExpression(sprintf(
"JSON_VALUE(%s, '$.field_id')",
DBmysql::quoteName('extra_data'),
)),
]);
if (!empty($found)) {
$question->getFromDB(current($found)['id']);
Session::addMessageAfterRedirect(
msg: $question->formatSessionMessageAfterAction(sprintf(
__('The field "%s" cannot be deleted because it is used in a form question', 'fields'),
$this->fields['label'],
)),
message_type: ERROR,
);
return false;
}

//retrieve search option ID to clean DiplayPreferences
$container_obj = new PluginFieldsContainer();
$container_obj->getFromDB($this->fields['plugin_fields_containers_id']);
Expand Down
Loading