Skip to content

Add CompatForm based version of ConfigForm#5480

Open
TheSyscall wants to merge 5 commits intomainfrom
config-form-5479
Open

Add CompatForm based version of ConfigForm#5480
TheSyscall wants to merge 5 commits intomainfrom
config-form-5479

Conversation

@TheSyscall
Copy link
Copy Markdown

@TheSyscall TheSyscall commented Mar 23, 2026

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.

This form can optionally be used to delete a section of the configuration file or create a new one.

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
Copy link
Copy Markdown
Member

@Al2Klimov Al2Klimov left a comment

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
  3. yum remove icingaweb2-module-monitoring
  4. Downgrade to https://git.icinga.com/packages/icingaweb/-/jobs/856109
  5. tar -C /usr/share/icingaweb2/modules -vxzf ~fedora/test5480.tgz
  6. icingacli mod en test5480
  7. Visit /icingaweb2/test5480
  8. Input something
  9. Press enter
  10. cat /etc/icingaweb2/modules/test5480/config.ini
  11. Ok
  12. chmod 0440 /etc/icingaweb2/modules/test5480/config.ini
  13. Repeat steps 7-9
  14. Fails

Seems to work. So far – so good.

test5480.tgz

t('Saving Configuration Failed!'),
));

$this->addHtml(HtmlElement::create(
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.

I wonder whether multiple individual HtmlElements are necessary...

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

ShowConfiguration perfectly mimics the old showConfiguration.phtml. (Except adding the copy to clipboard button)

$this->config->getConfigFile(),
$this->exception->getMessage(),
),
HtmlString::create('<br>'),
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.

I'd use multiple p instead of br.

@flourish86 What do you think?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

ShowConfiguration perfectly mimics the old showConfiguration.phtml. (Except adding the copy to clipboard button)

But yes, I'm totally open for a new design and/layout and an HTML rework.

$value = $this->getConfigValue($element->getName());

$configSection = $this->config->getSection($section);
if (empty($value)) {
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.

php -r 'echo (int) empty("0");' says "1", so empty() seems not the best idea, does it?

Copy link
Copy Markdown
Author

@TheSyscall TheSyscall Apr 2, 2026

Choose a reason for hiding this comment

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

I have no problems with storing "0" values in the configuration.
Since it could be any type of element here, I don't think there is a reliable way determine if the field should be included or not.

if ($this->isCreateForm()) {
$this->section = $this->getValue(static::NAME_ELEMENT_NAME);

if (empty($this->section)) {
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.

I have no idea about this section stuff, but it sounds interesting...

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

It is pretty common for configuration files that manage multiple identical instances of something (resources, users, pdf print backends, etc.).

So this new ConfigForm supports being pointed to a specific section and handling just that. (updaing and deleting)
It also can be used to create a new section.

An alternative way to having all three possible use cases in one form would be to split it up into two. Something like ConfigForm for the whole INI-file and ConfigSectionForm That focuses just one section, possibly creating or deleting it.

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.

Kind of a reference implementation would be helpful for testing.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

There already is an implementation this class in "section mode" in Icinga/icingaweb2-module-pdfexport#88

TheSyscall added a commit to Icinga/icingaweb2-module-pdfexport that referenced this pull request Apr 7, 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

2 participants