I have created a configuration form in Grav's admin panel, and I want to extend/modify some of it's values on save. More precisely, I have a list form element that looks like this in the blueprint:
topics:
type: list
fields:
.name:
type: text
.unique_id:
type: text
readonly: true
default: generate_on_save
On save, I want to replace all generate_on_save
values with a unique id.
I tried to hook into the onAdminSave Event, but the Event Object contained just an instance of \Grav\Common\Data\Blueprint and no actual form data. I then tried to modify the request object, but when I register the modified request in the grav container, I get an error Cannot override frozen service 'request'
.
How can I accomplish this task?
I did the following which works fine:
public function onAdminSave(Event $event) {
/** @var Data */
$form = $event['object'];
$topics = $form['topics'];
foreach ($topics as &$topic) {
if ($topic['unique_id'] === 'generate_on_save') {
$topic['unique_id'] = str_rot13($topic['name']);
}
}
// Note: Updated $form['topics'] must be re-assigned
$form['topics'] = $topics;
}