/**
* Generate form and display
*
* @return \Zend\View\Model\ViewModel|array
*/
public function editAction()
{
$coreConfig = $this->getServiceLocator()->get('CoreConfig');
$values = $coreConfig->getValues();
$this->form->setAttribute('action', $this->url()->fromRoute($this->getRouteMatch()->getMatchedRouteName()));
$this->form->setValues($values);
if ($this->getRequest()->isPost()) {
$this->form->setData($this->getRequest()->getPost()->toArray());
if (!$this->form->isValid()) {
$this->flashMessenger()->addErrorMessage('Can not save configuration');
$this->useFlashMessenger();
} else {
$inputs = $this->form->getInputFilter()->getValidInput();
foreach ($inputs as $input) {
if (method_exists($input, 'getName')) {
$coreConfig->setValue($input->getName(), $input->getValue());
}
}
$this->flashMessenger()->addSuccessMessage('Configuration saved');
return $this->redirect()->toRoute($this->getRouteMatch()->getMatchedRouteName());
}
}
return array('form' => $this->form);
}