/**
* Validate the form
*/
private function validateForm()
{
if ($this->frm->isSubmitted()) {
$bundledActionPermissions = array();
// cleanup the submitted fields, ignore fields that were added by hackers
$this->frm->cleanupFields();
// get fields
$nameField = $this->frm->getField('name');
// loop through modules
foreach ($this->modules as $module) {
// loop through actions
foreach ($this->actions[$module['value']] as $action) {
// collect permissions if not bundled
if (!array_key_exists('group', $action)) {
$actionPermissions[] = $this->frm->getField('actions_' . $module['label'] . '_' . $action['label']);
}
}
// loop through bundled actions
foreach ($this->actionGroups as $key => $group) {
// loop through all fields
foreach ($this->frm->getFields() as $field) {
// field exists?
if ($field->getName() == 'actions_' . $module['label'] . '_' . 'Group_' . \SpoonFilter::ucfirst($key)) {
// add to bundled actions
$bundledActionPermissions[] = $this->frm->getField('actions_' . $module['label'] . '_' . 'Group_' . \SpoonFilter::ucfirst($key));
}
}
}
}
// loop through widgets and collect presets
foreach ($this->widgets as $widget) {
$widgetPresets[] = $this->frm->getField('widgets_' . $widget['checkbox_name']);
}
// validate fields
$nameField->isFilled(BL::err('NameIsRequired'));
// new name given?
if ($nameField->getValue() !== $this->record['name']) {
// group already exists?
if (BackendGroupsModel::alreadyExists($nameField->getValue())) {
$nameField->setError(BL::err('GroupAlreadyExists'));
}
}
// no errors?
if ($this->frm->isCorrect()) {
// update widgets
$group = $this->updateWidgets($widgetPresets);
// update permissions
$this->updatePermissions($actionPermissions, $bundledActionPermissions);
// trigger event
BackendModel::triggerEvent($this->getModule(), 'after_edit', array('item' => $group));
// everything is saved, so redirect to the overview
$this->redirect(BackendModel::createURLForAction('Index') . '&report=edited&var=' . urlencode($group['name']) . '&highlight=row-' . $group['id']);
}
}
}