Skip to content

Commit eb9719c

Browse files
authored
feat(forms): add Fields question type and category implementation (#1060)
* feat(forms): add Fields question type and category implementation * fix: Rector lint * fix: Twig lint * fix: PHPStan + remove code duplication
1 parent 25c9d05 commit eb9719c

21 files changed

+2103
-59
lines changed

.gitignore

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
dist/
2-
vendor/
1+
/dist/
2+
/node_modules/
3+
/vendor/
34
.gh_token
5+
.phpunit.result.cache
6+
tests/files/
47
*.min.*

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](http://keepachangelog.com/)
66
and this project adheres to [Semantic Versioning](http://semver.org/).
77

8-
98
## [UNRELEASED]
109

10+
### Added
11+
12+
- Implement `Field` question type for new GLPI forms
13+
1114
## [1.22.2] - 2025-10-24
1215

1316
### Fixed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
include ../../PluginsMakefile.mk

inc/field.class.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
use Glpi\Features\Clonable;
3131
use Glpi\DBAL\QueryExpression;
3232
use Glpi\Application\View\TemplateRenderer;
33+
use Glpi\Form\Question;
3334

3435
class PluginFieldsField extends CommonDBChild
3536
{
@@ -350,6 +351,27 @@ public function pre_deleteItem()
350351
*/
351352
global $DB;
352353

354+
// Check if the field is used in a form question
355+
$question = new Question();
356+
$found = $question->find([
357+
'type' => PluginFieldsQuestionType::class,
358+
$this->fields['id'] => new QueryExpression(sprintf(
359+
"JSON_VALUE(%s, '$.field_id')",
360+
DBmysql::quoteName('extra_data'),
361+
)),
362+
]);
363+
if (!empty($found)) {
364+
$question->getFromDB(current($found)['id']);
365+
Session::addMessageAfterRedirect(
366+
msg: $question->formatSessionMessageAfterAction(sprintf(
367+
__('The field "%s" cannot be deleted because it is used in a form question', 'fields'),
368+
$this->fields['label'],
369+
)),
370+
message_type: ERROR,
371+
);
372+
return false;
373+
}
374+
353375
//retrieve search option ID to clean DiplayPreferences
354376
$container_obj = new PluginFieldsContainer();
355377
$container_obj->getFromDB($this->fields['plugin_fields_containers_id']);

0 commit comments

Comments
 (0)