You are not logged in.

Announcement

 Téléchargez la dernière version stable de GLPI      -     Et vous, que pouvez vous faire pour le projet GLPI ? :  Contribuer
 Download last stable version of GLPI                      -     What can you do for GLPI ? :  Contribute

#1 2024-02-20 14:58:11

jmeuh
Member
Registered: 2021-11-09
Posts: 7

Adding foreign key field to form

Hi,
I am making a modification to the "badges" module.
I added a ...accessdetails table:

DROP TABLE IF EXISTS `glpi_plugin_badges_badgeaccessdetails`;
CREATE TABLE `glpi_plugin_badges_badgeaccessdetails` (
   `id` int unsigned NOT NULL auto_increment,
   `name` varchar(255) collate utf8mb4_unicode_ci default NULL,
   `plugin_badges_badgeaccesses_id` int unsigned NOT NULL DEFAULT '0',
   PRIMARY KEY  (`id`),
   KEY `plugin_badges_badgeaccesses_id` (`plugin_badges_badgeaccesses_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC;

The form is automatically generated but does not display the "plugin_badges_badgeaccesses_id" field

Does anyone know how to do this?



CODE: (inspired by badgetype)

badgeaccessdetail.class.php

if (!defined('GLPI_ROOT')) {
   die("Sorry. You can't access directly to this file");
}

/**
 * Class PluginBadgesBadgeAccessDetail
 */
class PluginBadgesBadgeAccessDetail extends CommonDropdown {

   static $rightname         = "dropdown";
   var    $can_be_translated = true;

   /**
    * @param int $nb
    *
    * @return translated
    */
   static function getTypeName($nb = 0) {
      return _n("Liste d'accès par site", "Liste d'accès par site", $nb, 'badges');
   }

badgeaccessdetail.php

include('../../../inc/includes.php');

$dropdown = new PluginBadgesBadgeAccessDetail();
include(GLPI_ROOT . "/front/dropdown.common.php");

badgeaccessdetail.form.php

include('../../../inc/includes.php');

$dropdown = new PluginBadgesBadgeAccessDetail();
include(GLPI_ROOT . "/front/dropdown.common.form.php");

Offline

#2 2024-02-21 01:10:33

cconard96
Moderator
Registered: 2018-07-31
Posts: 2,809
Website

Re: Adding foreign key field to form

The only reason the name field shows is because it is a common field that all dropdowns have and therefore is automatically handled.
See the "showForm" method in src/CommonDropdown.php (GLPI source code) to see how dropdown forms are shown by default.


GLPI Collaborator and Plugin Developer.
My non-English comments are automated translations. Sorry for any confusion that causes.
Mes commentaires non anglais sont des traductions automatiques. Désolé pour toute confusion qui cause.
Mis comentarios que no están en inglés son traducciones automáticas. Perdón por cualquier confusión que cause.

Offline

#3 2024-02-21 17:26:49

jmeuh
Member
Registered: 2021-11-09
Posts: 7

Re: Adding foreign key field to form

Thank you for your reply.

I looked at how "showForm" is used. I don't understand how this function can allow me to add a field to my form.

Do you have an example?

Offline

Board footer

Powered by FluxBB