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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Fixed

- Fix search crash when two containers share a dropdown field with the same name.
- Prevent table and file regeneration when label and/or name is updated.

## [1.24.2] - 2026-06-30

Expand Down
22 changes: 20 additions & 2 deletions inc/container.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,12 @@ public function defineTabs($options = [])

public function prepareInputForUpdate($input)
{
return PluginFieldsToolbox::prepareLabel($input);
if (isAPI() || isset($input['form_submission']) ) {
unset($input['label']);
unset($input['name']);
}

return $input;
}
Comment thread
stonebuzz marked this conversation as resolved.

public function prepareInputForAdd($input)
Expand Down Expand Up @@ -970,10 +975,23 @@ public function showForm($ID, $options = [])
echo '<tr>';
echo "<td width='20%'>" . __('Label') . ' : </td>';
echo "<td width='30%'>";
$label_options = [
'value' => $this->fields['label'],
];

if (!$this->isNewID($ID)) {
$label_options['readonly'] = true;
}

echo Html::input(
'label',
$label_options,
);

echo Html::hidden(
'form_submission',
[
'value' => $this->fields['label'],
'value' => true,
],
);
echo '</td>';
Expand Down
57 changes: 57 additions & 0 deletions tests/Units/ContainerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
use GlpiPlugin\Field\Tests\FieldTestTrait;
use PHPUnit\Framework\Attributes\DataProvider;
use PluginFieldsContainer;
use Ticket;

require_once __DIR__ . '/../FieldTestCase.php';

Expand Down Expand Up @@ -106,4 +107,60 @@ public function testAddWithValidItemtypesSucceeds(): void

$this->assertGreaterThan(0, $container->getID());
}

public function testPrepareInputForUpdateStripsLabelAndNameOnFormSubmission(): void
{
$container = new PluginFieldsContainer();
$input = [
'label' => 'New Label',
'name' => 'new_name',
'form_submission' => true,
'is_active' => 1,
];

$result = $container->prepareInputForUpdate($input);

$this->assertArrayNotHasKey('label', $result);
$this->assertArrayNotHasKey('name', $result);
$this->assertArrayHasKey('is_active', $result);
}

public function testPrepareInputForUpdatePreservesNameAndLabelForMigration(): void
{
$container = new PluginFieldsContainer();
$input = [
'name' => 'migration_corrected_name',
'label' => 'Some Label',
'itemtypes' => '["Computer"]',
];

$result = $container->prepareInputForUpdate($input);

$this->assertSame('migration_corrected_name', $result['name']);
$this->assertArrayHasKey('label', $result);
}

public function testUpdateNameViaMigrationPathPersistsInDatabase(): void
{
$container = $this->createFieldContainer([
'label' => 'MigrationPath ' . $this->getUniqueString(),
'type' => 'tab',
'itemtypes' => [Computer::class],
'is_active' => 1,
'entities_id' => 0,
'is_recursive' => 1,
]);

$original_name = $container->fields['name'];
$new_name = 'mig_' . substr($original_name, 0, 20);

$container->update(['id' => $container->getID(), 'name' => $new_name]);

$refreshed = new PluginFieldsContainer();
$refreshed->getFromDB($container->getID());
$this->assertSame($new_name, $refreshed->fields['name']);

// Restore original name so teardown can locate and drop the physical table
$container->update(['id' => $container->getID(), 'name' => $original_name]);
}
}
Loading