Add Config based on CompatForm#5480
Conversation
Now requires Icinga/icingaweb2#5480
4ab944a to
13eff40
Compare
Now requires Icinga/icingaweb2#5480
804ecea to
5f76490
Compare
94ee656 to
9bb214a
Compare
| /** | ||
| * Form base-class providing standard functionality for configuration forms | ||
| */ | ||
| class ConfigForm extends CompatForm |
There was a problem hiding this comment.
Test
- Install Fedora 42
- Apply https://github.com/Al2Klimov/ansible-icinga-fedora using snapshot packages
yum remove icingaweb2-module-monitoring- Upgrade to https://git.icinga.com/packages/icingaweb/-/jobs/905522
- Create
/usr/share/icingaweb2/modules/test5480 icingacli mod en test5480- Visit /icingaweb2/test5480
- Input something
Press entercat /etc/icingaweb2/modules/test5480/config.ini(ok)chmod 0440 /etc/icingaweb2/modules/test5480/config.ini- 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);
}
}| * 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. |
There was a problem hiding this comment.
| * 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.
There was a problem hiding this comment.
Mistakes were made during refactor. Fixed it.
b70dd6c to
4dba4e0
Compare
4dba4e0 to
51fb44a
Compare
51fb44a to
ee95ab4
Compare
jrauh01
left a comment
There was a problem hiding this comment.
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.
f55d4e4 to
df34fa0
Compare
jrauh01
left a comment
There was a problem hiding this comment.
Please look over ShowConfiguration and inline the element creations where possible.
7147060 to
d77e48e
Compare
lippserd
left a comment
There was a problem hiding this comment.
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 : []; | ||
| } |
There was a problem hiding this comment.
| } | |
| * @return array{?string, ?string} TODO: Change docs. | |
| */ | |
| protected function getIniKeyFromName(string $name): array | |
| { | |
| return Str::symmetricSplit($name, $this->sectionKeyDelimiter, 2); | |
| } |
There was a problem hiding this comment.
Changed method signature
| $parts = $this->getIniKeyFromName($name); | ||
| if (count($parts) !== 2) { | ||
| return $default; | ||
| } | ||
|
|
||
| return $this->config->get($parts[0], $parts[1], $default); |
There was a problem hiding this comment.
| $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); |
There was a problem hiding this comment.
Changed call sites
d77e48e to
fbd41b8
Compare
97b1f15 to
9d50bc0
Compare
jrauh01
left a comment
There was a problem hiding this comment.
Overall this looks good, I would only adjust those two lines to stay consistent.
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.
1f65629 to
6081235
Compare
CompatForm based version of ConfigFormConfig based on CompatForm
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