public function getFlexiFormObject($identifier = null)
 {
     // by default, we assume the flexi form is the controller's data record.
     // You may provide an identifier or override as neccessary.
     $flexi = $this->flexiform_object ?: $this->owner->data();
     if ($identifier && !($flexi = FlexiFormUtil::GetFlexiByIdentifier($identifier))) {
         throw new Exception("No Flexi with identifier `{$identifier}` found");
     }
     if (!$flexi->hasExtension('FlexiFormExtension')) {
         throw new Exception('Flexi Form not found. Try passing an Identifier, or setting.');
     }
     return $flexi;
 }
 public function checkAccessAction($action)
 {
     return $action != 'httpSubmission' && FlexiFormUtil::GetFlexiByIdentifier($action) ? true : parent::checkAccessAction($action);
 }
 public function validate(ValidationResult $result)
 {
     $names = array();
     if ($result->valid()) {
         foreach ($this->owner->FlexiFormFields() as $field) {
             if (empty($field->Name)) {
                 $result->error("Field names cannot be blank. Encountered a blank {$field->Label()} field.");
                 break;
             }
             if (in_array($field->Name, $names)) {
                 $result->error("Field Names must be unique per form. {$field->Name} was encountered more than once.");
                 break;
             } else {
                 $names[] = $field->Name;
             }
             $default_value = $field->DefaultValue;
             if (!empty($default_value) && $field->Options()->exists() && !in_array($default_value, $field->Options()->column('Value'))) {
                 $result->error("The default value of {$field->getName()} must exist as an option value");
                 break;
             }
         }
         if ($this->FlexiFormID() && ($flexi = FlexiFormUtil::GetFlexiByIdentifier($this->FlexiFormID()))) {
             if ($flexi->ID != $this->owner->ID) {
                 $result->error('Form Identifier in use by another form.');
             }
         }
     }
 }