public function getFormFieldFromEditableFormField(EditableFormField $fieldRecord)
 {
     $field = $fieldRecord->getFormField();
     // Remove templates added by EditableFormField
     $field->setFieldHolderTemplate(null);
     $field->setTemplate(null);
     // Simplify dropdown to only have options that are used
     if ($field->hasMethod('getSource')) {
         $source = $field->getSource();
         $availableSources = SubmittedFormField::get()->filter(array('ParentID' => $this->controller->data()->PublishedSubmittedFormIDs(), 'Name' => $fieldRecord->Name, 'Value' => array_keys($source)))->column('Value');
         if (!$availableSources) {
             // Don't show the field if there is nothing to search on.
             return null;
         }
         $newSources = array();
         foreach ($availableSources as $value) {
             if (isset($source[$value])) {
                 $newSources[$value] = $source[$value];
             }
         }
         if (!$newSources) {
             // Don't show the field if there is nothing to search on.
             return null;
         }
         $field->setSource($newSources);
     }
     if ($field->hasMethod('setHasEmptyDefault') && ($dropdownEmptyString = $this->config()->dropdown_empty_string)) {
         // Defaults to '- Please select -', configured above.
         $field->setEmptyString($dropdownEmptyString);
     }
     // Attach EditableFormField to differentiate EditableFormField fields from regular ones
     // in the form.
     $field->EditableFormField = $fieldRecord;
     return $field;
 }
示例#2
0
 function getFormField()
 {
     if ($field = parent::getFormField()) {
         return $field;
     }
     return new FileField($this->Name, $this->Title, $this->getField('Default'));
     // TODO We can't use the preview feature because FileIFrameField also shows the "From the file store" functionality
     //return new FileIFrameField( $this->Name, $this->Title, $this->getField('Default') );
 }
 public function processNext(EditableFormField $field)
 {
     $formField = $field->getFormField();
     if (!$formField) {
         return $this;
     }
     $this->push($formField);
     if ($formField instanceof UserFormsFieldContainer) {
         return $formField->setParent($this);
     }
     return $this;
 }