Redmine/inc/entity.class.php
Gemini c8765ca5ff fix: custom fields obrigatórios na criação de projeto + identifier lowercase (1.5.6)
- form das abas Redmine exibe/envia custom_field_values (Tipo de Projeto etc.)
- createProjectFull normaliza o identificador (minúsculas)
- sync da aba de projeto usa syncMetadata completo (não apaga mais o cache)

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-02 09:53:23 -03:00

86 lines
3.3 KiB
PHP

<?php
if (!defined('GLPI_ROOT')) {
die("Sorry. You can't access this file directly");
}
class PluginRedmineEntity extends CommonDBTM {
static function getTypeName($nb = 0) {
return 'Redmine';
}
function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) {
if ($item->getType() == 'Entity') {
return self::createTabEntry(__('Redmine', 'redmine'), 0, $item::getType(), 'fas fa-sitemap');
}
return '';
}
static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0) {
if ($item->getType() == 'Entity') {
self::showForEntity($item);
}
return true;
}
static function getIcon() {
return 'fas fa-sitemap';
}
static function showForEntity(Entity $entity) {
global $DB, $CFG_GLPI;
$entities_id = $entity->getID();
$form_url = $CFG_GLPI['root_doc'] . '/plugins/redmine/front/entity.form.php';
// {id: name} montado no PHP (Twig merge corrompe chaves inteiras).
$project_options = PluginRedmineProject::getRedmineProjectOptions();
// Already linked?
$iterator = $DB->request([
'FROM' => 'glpi_plugin_redmine_entities',
'WHERE' => ['entities_id' => $entities_id]
]);
if (count($iterator) > 0) {
$link = $iterator->current();
$redmineProjectId = (int) $link['redmine_project_id'];
$cat_options = [];
foreach (PluginRedmineRedmineapi::getProjectCategories($redmineProjectId) as $c) {
if (isset($c['id'], $c['name'])) {
$cat_options[$c['id']] = $c['name'];
}
}
\Glpi\Application\View\TemplateRenderer::getInstance()->display('@redmine/project_linked.html.twig', [
'action_url' => $form_url,
'owner_field' => 'entities_id',
'owner_id' => $entities_id,
'redmine_project_id' => $redmineProjectId,
'redmine_project_name' => $project_options[$redmineProjectId] ?? '',
'cat_options' => $cat_options,
'default_category_id' => (int) ($link['default_category_id'] ?? 0),
'csrf_token_value' => Session::getNewCSRFToken(),
]);
return;
}
// Not linked: show the link/create form (reuses the project tab template).
$description = \Glpi\RichText\RichText::getTextFromHtml($entity->fields['comment'] ?? '', false, true, true);
\Glpi\Application\View\TemplateRenderer::getInstance()->display('@redmine/project_form.html.twig', [
'action_url' => $form_url,
'owner_field' => 'entities_id',
'owner_id' => $entities_id,
'project_options' => PluginRedmineProject::getRedmineProjectOptions(true),
'custom_fields' => PluginRedmineProject::getProjectCustomFieldDefs(),
'project_name' => $entity->fields['name'],
'project_description' => $description,
'project_identifier' => 'glpi-ent-' . $entities_id,
'modules' => PluginRedmineProject::getModules(),
'csrf_token_value' => Session::getNewCSRFToken()
]);
}
}