public function scaffoldFormField($title = null, $params = null)
 {
     if (empty($this->object)) {
         return null;
     }
     $relationName = substr($this->name, 0, -2);
     $hasOneClass = DataObject::getSchema()->hasOneComponent(get_class($this->object), $relationName);
     if (empty($hasOneClass)) {
         return null;
     }
     $hasOneSingleton = singleton($hasOneClass);
     if ($hasOneSingleton instanceof File) {
         $field = new UploadField($relationName, $title);
         if ($hasOneSingleton instanceof Image) {
             $field->setAllowedFileCategories('image/supported');
         }
         return $field;
     }
     // Build selector / numeric field
     $titleField = $hasOneSingleton->hasField('Title') ? "Title" : "Name";
     $list = DataList::create($hasOneClass);
     // Don't scaffold a dropdown for large tables, as making the list concrete
     // might exceed the available PHP memory in creating too many DataObject instances
     if ($list->count() < 100) {
         $field = new DropdownField($this->name, $title, $list->map('ID', $titleField));
         $field->setEmptyString(' ');
     } else {
         $field = new NumericField($this->name, $title);
     }
     return $field;
 }
 public function scaffoldSearchField($title = null)
 {
     $anyText = _t('Boolean.ANY', 'Any');
     $source = array(1 => _t('Boolean.YESANSWER', 'Yes'), 0 => _t('Boolean.NOANSWER', 'No'));
     $field = new DropdownField($this->name, $title, $source);
     $field->setEmptyString("({$anyText})");
     return $field;
 }
 /**
  * Create a test dropdown field, with the option to
  * set what source and blank value it should contain
  * as optional parameters.
  *
  * @param string|null $emptyString The text to display for the empty value
  * @param string|integer $value The default value of the field
  * @return DropdownField object
  */
 public function createDropdownField($emptyString = null, $value = '')
 {
     /* Set up source, with 0 and 1 integers as the values */
     $source = array(0 => 'No', 1 => 'Yes');
     $field = new DropdownField('Field', null, $source, $value);
     if ($emptyString !== null) {
         $field->setEmptyString($emptyString);
     }
     return $field;
 }
 /**
  * Get the search context from {@link File}, used to create the search form
  * as well as power the /search API endpoint.
  *
  * @return SearchContext
  */
 public function getSearchContext()
 {
     $context = File::singleton()->getDefaultSearchContext();
     // Customize fields
     $dateHeader = HeaderField::create('Date', _t('CMSSearch.FILTERDATEHEADING', 'Date'), 4);
     $dateFrom = DateField::create('CreatedFrom', _t('CMSSearch.FILTERDATEFROM', 'From'))->setConfig('showcalendar', true);
     $dateTo = DateField::create('CreatedTo', _t('CMSSearch.FILTERDATETO', 'To'))->setConfig('showcalendar', true);
     $dateGroup = FieldGroup::create($dateHeader, $dateFrom, $dateTo);
     $context->addField($dateGroup);
     /** @skipUpgrade */
     $appCategories = array('archive' => _t('SilverStripe\\AssetAdmin\\Controller\\AssetAdmin.AppCategoryArchive', 'Archive'), 'audio' => _t('SilverStripe\\AssetAdmin\\Controller\\AssetAdmin.AppCategoryAudio', 'Audio'), 'document' => _t('SilverStripe\\AssetAdmin\\Controller\\AssetAdmin.AppCategoryDocument', 'Document'), 'flash' => _t('SilverStripe\\AssetAdmin\\Controller\\AssetAdmin.AppCategoryFlash', 'Flash', 'The fileformat'), 'image' => _t('SilverStripe\\AssetAdmin\\Controller\\AssetAdmin.AppCategoryImage', 'Image'), 'video' => _t('SilverStripe\\AssetAdmin\\Controller\\AssetAdmin.AppCategoryVideo', 'Video'));
     $context->addField($typeDropdown = new DropdownField('AppCategory', _t('SilverStripe\\AssetAdmin\\Controller\\AssetAdmin.Filetype', 'File type'), $appCategories));
     $typeDropdown->setEmptyString(' ');
     $currentfolderLabel = _t('SilverStripe\\AssetAdmin\\Controller\\AssetAdmin.CurrentFolderOnly', 'Limit to current folder?');
     $context->addField(new CheckboxField('CurrentFolderOnly', $currentfolderLabel));
     $context->getFields()->removeByName('Title');
     return $context;
 }