/**
  * Create a list of fields to show in the register form.
  *
  * @param TripolisProvider $provider
  * @param                  $database
  * @param                  $fields
  *
  * @return array
  * @throws \Exception
  * @throws \SoapFault
  * @throws \Exception
  */
 protected function getFieldDefinitions(TripolisProvider $provider, $database, $fields)
 {
     // Try gracefully, so not to upset the non-programmers
     try {
         $fieldGroups = $provider->ContactDatabaseFieldGroup()->database($database)->all();
         $tableFields = $provider->ContactDatabaseField()->database($database)->all();
     } catch (\SoapFault $f) {
         if (!WP_DEBUG) {
             return array();
         } else {
             throw $f;
         }
     } catch (\Exception $e) {
         if (!WP_DEBUG) {
             return array();
         } else {
             throw $e;
         }
     }
     $postData = isset($_POST[$this->plugin]) ? $_POST[$this->plugin] : false;
     $definition = array();
     if (!$fields) {
         $fields = array_keys($tableFields);
     }
     foreach ($fields as $field) {
         if (isset($tableFields[$field])) {
             $id = implode('_', array($this->plugin, $fieldGroups[$tableFields[$field]->contactDatabaseFieldGroupId]->name, $tableFields[$field]->name));
             $required = apply_filters($this->plugin . '_required', $tableFields[$field]->required, $tableFields[$field]);
             $classes = array($this->plugin, strtolower($tableFields[$field]->type));
             if ($required) {
                 $classes[] = 'required';
             }
             $definition[$field] = array('code' => $field, 'label' => apply_filters($this->plugin . '_label', $tableFields[$field]->label, $tableFields[$field]), 'name' => $this->getUniqueId() . '[' . $field . ']', 'id' => $id, 'value' => apply_filters($this->plugin . '_value', isset($postData[$field]) ? $postData[$field] : '', $tableFields[$field]), 'type' => $tableFields[$field]->type, 'required' => $required, 'class' => apply_filters($this->plugin . '_classes', $classes, $tableFields[$field]), 'group' => $fieldGroups[$tableFields[$field]->contactDatabaseFieldGroupId], 'message' => '');
         }
     }
     return $definition;
 }