I always feel like I'm posting to the wrong place on the forums, but I'm taking a stab at this again.
I'm using a CheckboxSetField to add multiple brand names to each PDF that's uploaded to a technical documents section of the site.
I need to be able to search the different PDF files using "Brands" as a field, but I wan to be able to pass the array of options to a dropdown, rather than a text search.
Using ComplexSearch, is there a way to pass the array from the CheckboxSetField to a dropdown?
<?php
class TechDoc extends DataObject
{
static $db = array (
'Name' => 'Text',
'Brand' => 'Varchar',
'Description' => 'Text',
'Language' => "Enum('English, French, Spanish, Portuguese, Polish, German')"
);
static $has_one = array (
'Attachment' => 'File',
'TechDocPage' => 'TechDocPage'
);
static $has_many = array(
'TechDoc' => 'Brand'
);
public function getCMSFields_forPopup()
{
return new FieldSet(
new TextField('Name'),
new TextareaField('Description'),
new CheckboxSetField('Brand','Brand',(array ("BrandA" => "BrandA","BrandB" => "BrandB","BrandC" => "BrandC"))),
new DropdownField('Language','Language', singleton('TechDoc')->dbObject('Language')->enumValues()),
new FileIFrameField('Attachment')
);
}
static $searchable_fields = array(
'Name' => 'PartialMatchFilter',
'Language' => 'ExactMatchFilter',
'Description' => 'PartialMatchFilter',
/*This does work, but I need a dropdown*/
'Brand' => 'PartialMatchFilter'
/*This does not work, since I can't pass it the array for the dropdown:
'Brand' => array(
'title' => 'Brand',
'field' => 'DropdownField',
'filter' => 'PartialMatchFilter'
),*/
);
public function getCustomSearchContext() {
$fields = $this->scaffoldSearchFields(array(
'restrictFields' => array(
'Name',
'Brand',
'Language',
'Type'
)
));
/*This seems redundant, but I'm working from the tutorial...*/
$filters = array(
'Name' => new PartialMatchFilter('Name'),
'Brand' => new PartialMatchFilter('Brand'),
'Language' => new ExactMatchFilter('Language'),
'Type' => new PartialMatchFilter('Type')
);
return new SearchContext(
$this->class,
$fields,
$filters
);
}
}
?>
If there's a better way to do this, I'm perfectly happy to know how I might change this ;-).
Thanks in advance.