Hello,
I'm trying to do the following: When a user saves a page I want to populate some fields on the same page. For example: calculate the ratio of an image and save it in a hidden field.
I've created a Module and populate the field in a beforeSave hook. But my manually populated field doesn't get saved. I guess I have to call $page->save() in order to save the field, but this would lead to an infinite loop. Because I populate the field in a beforeSave hook shouldn't the page save the field right after the execution of my hook?
<?php
class ItemHooks extends WireData implements Module {
public static function getModuleInfo() {
return array(
'title' => 'item hooks',
'version' => 100,
'summary' => 'add item hooks to process items after beeing saved',
'href' => '',
'singular' => true,
'autoload' => true
);
}
public function init() {
$this->pages->addHookBefore('save', $this, 'handleSave');
}
public function handleSave($event) {
$page = $event->arguments('page');
$fields = $page->fields;
$field = $fields->get('hidden_field');
$field->set('value', 'test');
$fields->save($field);
}
}
?>
thanks,
Arno