1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Represents a searchable class in Elastica for editing purposes |
5
|
|
|
*/ |
6
|
|
|
class SearchableClass extends DataObject { |
7
|
|
|
|
8
|
|
|
private static $db = array('Name' => 'Varchar', 'InSiteTree' => 'Boolean'); |
9
|
|
|
|
10
|
|
|
private static $has_many = array('SearchableFields' => 'SearchableField'); |
|
|
|
|
11
|
|
|
|
12
|
|
|
private static $display_fields = array('Name', 'IsInSiteTreeHumanReadable'); |
|
|
|
|
13
|
|
|
|
14
|
|
|
|
15
|
|
|
public function getCMSFields() { |
16
|
|
|
|
17
|
|
|
$fields = new FieldList(); |
18
|
|
|
|
19
|
|
|
$fields->push( new TabSet( "Root", $mainTab = new Tab( "Main" ) ) ); |
20
|
|
|
$mainTab->setTitle( _t( 'SiteTree.TABMAIN', "Main" ) ); |
21
|
|
|
|
22
|
|
|
$fields->addFieldToTab( 'Root.Main', $nf = new TextField( 'Name', 'Name') ); |
23
|
|
|
$nf->setReadOnly(true); |
24
|
|
|
$nf->setDisabled(true); |
25
|
|
|
|
26
|
|
|
$config = GridFieldConfig_RecordEditor::create(); |
27
|
|
|
|
28
|
|
|
// remove add button |
29
|
|
|
$config->removeComponent($config->getComponentByType('GridFieldAddNewButton')); |
30
|
|
|
$config->removeComponent($config->getComponentByType('GridFieldDeleteAction')); |
31
|
|
|
|
32
|
|
|
$config->getComponentByType('GridFieldDataColumns')->setDisplayFields(array( |
|
|
|
|
33
|
|
|
'Name' => 'Name', |
34
|
|
|
'Weight' => 'Weighting', |
35
|
|
|
'Searchable' => 'Search this field?' |
36
|
|
|
)); |
37
|
|
|
|
38
|
|
|
|
39
|
|
|
$gridField = new GridField( |
40
|
|
|
'SearchableField', // Field name |
41
|
|
|
'Field Name', // Field title |
42
|
|
|
SearchableField::get()->filter('SearchableClassID', $this->ID)->sort('Name'), |
43
|
|
|
$config |
44
|
|
|
); |
45
|
|
|
|
46
|
|
|
$fields->addFieldToTab('Root.Main', $gridField); |
47
|
|
|
|
48
|
|
|
/* |
|
|
|
|
49
|
|
|
$fields = new FieldList(); |
50
|
|
|
$fields->addFieldToTab('Root.Main', new TextField('Name', 'Name')); |
51
|
|
|
|
52
|
|
|
|
53
|
|
|
*/ |
54
|
|
|
return $fields; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
|
58
|
|
|
public function IsInSiteTreeHumanReadable() { |
59
|
|
|
return $this->InSiteTree ? 'Yes' : 'No'; |
|
|
|
|
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|
This check marks private properties in classes that are never used. Those properties can be removed.