/**
  * Field edit method
  *
  * @return void
  */
 public function edit()
 {
     if (null === $this->request->getPath(1)) {
         Response::redirect($this->request->getBasePath());
     } else {
         $this->prepareView('fields.phtml', array('assets' => $this->project->getAssets(), 'acl' => $this->project->getService('acl'), 'phireNav' => $this->project->getService('phireNav')));
         $field = new Model\Field();
         $field->getById($this->request->getPath(1));
         // If field is found and valid
         if (isset($field->id)) {
             $this->view->set('title', $this->view->i18n->__('Structure') . ' ' . $this->view->separator . ' ' . $this->view->i18n->__('Fields') . ' ' . $this->view->separator . ' ' . $field->name)->set('data_title', $this->view->i18n->__('Structure') . ' ' . $this->view->separator . ' ' . $this->view->i18n->__('Fields') . ' ' . $this->view->separator . ' ');
             $form = new Form\Field($this->request->getBasePath() . $this->request->getRequestUri(), 'post', $field->id, $this->project->module('Phire'));
             // If form is submitted
             if ($this->request->isPost()) {
                 $form->setFieldValues($this->request->getPost(), array('htmlentities' => array(ENT_QUOTES, 'UTF-8')));
                 // If form is valid, save field
                 if ($form->isValid()) {
                     $field->update($form);
                     $this->view->set('id', $field->id);
                     if (null !== $this->request->getPost('update_value') && $this->request->getPost('update_value') == '1') {
                         Response::redirect($this->request->getBasePath() . '/edit/' . $field->id . '?saved=' . time());
                     } else {
                         if (null !== $this->request->getQuery('update')) {
                             $this->sendJson(array('updated' => ''));
                         } else {
                             Response::redirect($this->request->getBasePath() . '?saved=' . time());
                         }
                     }
                     // Else, re-render the form with errors
                 } else {
                     if (null !== $this->request->getQuery('update')) {
                         $this->sendJson($form->getErrors());
                     } else {
                         $this->view->set('form', $form);
                         $this->send();
                     }
                 }
                 // Else, render form
             } else {
                 $form->setFieldValues($field->getData(null, false));
                 $this->view->set('form', $form);
                 $this->send();
             }
             // Else, redirect
         } else {
             Response::redirect($this->request->getBasePath());
         }
     }
 }