Skip to content

Add Config based on CompatForm#5480

Merged
lippserd merged 1 commit into
mainfrom
config-form-5479
Jul 1, 2026
Merged

Add Config based on CompatForm#5480
lippserd merged 1 commit into
mainfrom
config-form-5479

Conversation

@TheSyscall

@TheSyscall TheSyscall commented Mar 23, 2026

Copy link
Copy Markdown
Contributor

An implementation of an INI based configuration form for CompatForms.

It allows developers to create a configuration form for an INI file and have it automatically populate form elements and store the results back into the specified file or section.

If writing the configuration file fails, an error is displayed alongside the full contents of the file to copy and paste manually by the admin.

As suggested here

resolves #5479

@TheSyscall TheSyscall self-assigned this Mar 23, 2026
@cla-bot cla-bot Bot added the cla/signed label Mar 23, 2026
TheSyscall added a commit to Icinga/icingaweb2-module-pdfexport that referenced this pull request Mar 23, 2026
@TheSyscall TheSyscall requested a review from Al2Klimov March 25, 2026 12:00
Al2Klimov

This comment was marked as resolved.

TheSyscall added a commit to Icinga/icingaweb2-module-pdfexport that referenced this pull request Apr 7, 2026
@TheSyscall TheSyscall requested a review from Al2Klimov April 16, 2026 11:40
@Al2Klimov Al2Klimov requested a review from flourish86 April 16, 2026 15:07
flourish86
flourish86 previously approved these changes Apr 28, 2026
@Al2Klimov Al2Klimov removed their request for review April 28, 2026 10:18
@TheSyscall TheSyscall requested a review from Al2Klimov May 22, 2026 08:16
@Al2Klimov Al2Klimov removed their request for review May 22, 2026 08:52
@TheSyscall TheSyscall requested a review from Al2Klimov May 22, 2026 11:53
/**
* Form base-class providing standard functionality for configuration forms
*/
class ConfigForm extends CompatForm

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test

  1. Install Fedora 42
  2. Apply https://github.com/Al2Klimov/ansible-icinga-fedora using snapshot packages
  3. yum remove icingaweb2-module-monitoring
  4. Upgrade to https://git.icinga.com/packages/icingaweb/-/jobs/905522
  5. Create /usr/share/icingaweb2/modules/test5480
  6. icingacli mod en test5480
  7. Visit /icingaweb2/test5480
  8. Input something
  9. Press enter
  10. cat /etc/icingaweb2/modules/test5480/config.ini (ok)
  11. chmod 0440 /etc/icingaweb2/modules/test5480/config.ini
  12. Repeat steps 7-9 (fails, prints helpful message)

So far so good...

/usr/share/icingaweb2/modules/test5480

library/Test5480/Form.php

<?php

namespace Icinga\Module\Test5480;

use Icinga\Web\Form\ConfigForm;

class Form extends ConfigForm
{
    protected function assemble()
    {
        $this->addElement('text', 'foo__bar');
    }
}

application/controllers/IndexController.php

<?php

namespace Icinga\Module\Test5480\Controllers;

use GuzzleHttp\Psr7\ServerRequest;
use Icinga\Module\Test5480\Form;
use ipl\Web\Compat\CompatController;

class IndexController extends CompatController
{
    public function indexAction(): void
    {
        $form = new Form($this->Config());
        $form->handleRequest(ServerRequest::fromGlobals());
        $this->addContent($form);
    }
}

@Al2Klimov Al2Klimov self-requested a review May 22, 2026 15:16
Al2Klimov

This comment was marked as resolved.

@Al2Klimov Al2Klimov self-requested a review May 26, 2026 11:00
Al2Klimov

This comment was marked as resolved.

@TheSyscall TheSyscall requested a review from Al2Klimov May 27, 2026 07:36
@Al2Klimov Al2Klimov removed their request for review May 27, 2026 08:01
@TheSyscall TheSyscall requested a review from Al2Klimov May 27, 2026 08:56
@TheSyscall TheSyscall requested a review from Al2Klimov June 23, 2026 08:01
Al2Klimov

This comment was marked as resolved.

@TheSyscall TheSyscall requested a review from Al2Klimov June 23, 2026 14:08
* Handle the deletion of the configuration section
*
* This method is called when the delete button is pressed.
* It deletes the underlying section regardless of whether form validation passed.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* It deletes the underlying section regardless of whether form validation passed.

Another round of throwing AI at your PR broke this promise:

Bildschirmaufnahme.2026-06-23.um.17.57.10.mov

You can just remove it if it's not super critical.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mistakes were made during refactor. Fixed it.

@jrauh01 jrauh01 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sometimes you do one line doc blocks for properties and sometimes multiline, but i cannot tell which pattern you are following. I think it would be better to standardize this.

Comment thread library/Icinga/Web/Form/ConfigSectionForm.php Outdated
Comment thread library/Icinga/Web/Form/ConfigForm.php
Comment thread library/Icinga/Web/Form/ConfigForm.php
Comment thread library/Icinga/Web/Form/ConfigForm.php
Comment thread library/Icinga/Web/Form/ConfigSectionForm.php Outdated
Comment thread library/Icinga/Web/Form/ConfigSectionForm.php Outdated
Comment thread library/Icinga/Web/Form/ConfigSectionForm.php Outdated
Comment thread library/Icinga/Web/Form/ConfigSectionForm.php Outdated
Comment thread library/Icinga/Web/Form/ConfigSectionForm.php Outdated
Comment thread library/Icinga/Web/Form/ConfigForm.php Outdated
@TheSyscall TheSyscall requested a review from jrauh01 June 26, 2026 08:30

@jrauh01 jrauh01 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please look over ShowConfiguration and inline the element creations where possible.

Comment thread library/Icinga/Web/Form/ConfigSectionForm.php Outdated
Comment thread library/Icinga/Web/Form/ConfigForm.php Outdated
Comment thread library/Icinga/Web/Form/ConfigForm.php Outdated
Comment thread library/Icinga/Web/Form/ConfigForm.php Outdated
Comment thread library/Icinga/Web/Form/ConfigSectionForm.php Outdated
@TheSyscall TheSyscall force-pushed the config-form-5479 branch 2 times, most recently from 7147060 to d77e48e Compare June 26, 2026 09:58

@lippserd lippserd left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed my mind, sorry. I think the suggestion is better than the current implementation. Make sure to adjust all call sites.

{
$parts = explode($this->sectionKeyDelimiter, $name, 2);
return count($parts) === 2 ? $parts : [];
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
}
* @return array{?string, ?string} TODO: Change docs.
*/
protected function getIniKeyFromName(string $name): array
{
return Str::symmetricSplit($name, $this->sectionKeyDelimiter, 2);
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed method signature

Comment thread library/Icinga/Web/Form/ConfigForm.php Outdated
Comment on lines +125 to +130
$parts = $this->getIniKeyFromName($name);
if (count($parts) !== 2) {
return $default;
}

return $this->config->get($parts[0], $parts[1], $default);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$parts = $this->getIniKeyFromName($name);
if (count($parts) !== 2) {
return $default;
}
return $this->config->get($parts[0], $parts[1], $default);
[$section, $key] = $this->getIniKeyFromName($name)
if ($key === null) {
return $default;
}
return $this->config->get($section, $key, $default);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed call sites

@lippserd lippserd added this to the 2.14.0 milestone Jun 26, 2026
Comment thread library/Icinga/Web/Widget/ShowConfiguration.php Outdated
Comment thread library/Icinga/Web/Widget/ShowConfiguration.php Outdated
Comment thread library/Icinga/Web/Form/ConfigSectionForm.php Outdated
@TheSyscall TheSyscall force-pushed the config-form-5479 branch 2 times, most recently from 97b1f15 to 9d50bc0 Compare June 29, 2026 07:10
@TheSyscall TheSyscall requested a review from jrauh01 June 30, 2026 06:11

@jrauh01 jrauh01 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall this looks good, I would only adjust those two lines to stay consistent.

Comment thread library/Icinga/Web/Form/ConfigForm.php Outdated
Comment thread library/Icinga/Web/Form/ConfigForm.php Outdated
CompatForm base class that uses a `section__key` element-name convention
to map form fields directly to INI file entries. Populates elements from
the config on assembly, writes changed values back on success (removing
empty keys, reverting empty password fields to their stored value), and
embeds the `ShowConfiguration` widget inline when saving fails.

@jrauh01 jrauh01 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@lippserd lippserd merged commit eb4fd0b into main Jul 1, 2026
13 checks passed
@lippserd lippserd deleted the config-form-5479 branch July 1, 2026 13:30
@lippserd lippserd changed the title Add CompatForm based version of ConfigForm Add Config based on CompatForm Jul 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Create an ipl\Compat\Form version of ConfigForm

5 participants