1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Sunnysideup\KeepWordsTogether; |
4
|
|
|
|
5
|
|
|
use SilverStripe\ORM\DataObject; |
6
|
|
|
use SilverStripe\ORM\Filters\PartialMatchFilter; |
7
|
|
|
|
8
|
|
|
class WordsToKeepTogether extends DataObject |
9
|
|
|
{ |
10
|
|
|
####################### |
11
|
|
|
### Names Section |
12
|
|
|
####################### |
13
|
|
|
|
14
|
|
|
private static $table_name = 'WordsToKeepTogether'; |
15
|
|
|
|
16
|
|
|
private static $singular_name = 'Words to keep together'; |
17
|
|
|
|
18
|
|
|
private static $plural_name = 'Entries of words to keep together'; |
19
|
|
|
|
20
|
|
|
private static $db = [ |
21
|
|
|
'Title' => 'Varchar', |
22
|
|
|
]; |
23
|
|
|
|
24
|
|
|
private static $indexes = [ |
25
|
|
|
'Title' => [ |
26
|
|
|
'type' => 'unique', |
27
|
|
|
], |
28
|
|
|
]; |
29
|
|
|
|
30
|
|
|
private static $default_sort = [ |
31
|
|
|
'Title' => 'ASC', |
32
|
|
|
]; |
33
|
|
|
|
34
|
|
|
private static $required_fields = [ |
35
|
|
|
'Title', |
36
|
|
|
]; |
37
|
|
|
|
38
|
|
|
private static $searchable_fields = [ |
39
|
|
|
'Title' => PartialMatchFilter::class, |
40
|
|
|
]; |
41
|
|
|
|
42
|
|
|
private static $field_labels = [ |
43
|
|
|
'Title' => 'Words', |
44
|
|
|
]; |
45
|
|
|
|
46
|
|
|
private static $field_labels_right = [ |
47
|
|
|
'Title' => 'e.g. New Zealand', |
48
|
|
|
]; |
49
|
|
|
|
50
|
|
|
private static $summary_fields = [ |
51
|
|
|
'Title' => 'Words', |
52
|
|
|
]; |
53
|
|
|
|
54
|
|
|
public function i18n_singular_name() |
55
|
|
|
{ |
56
|
|
|
return _t(self::class . '.SINGULAR_NAME', 'Words to keep together'); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function i18n_plural_name() |
60
|
|
|
{ |
61
|
|
|
return _t(self::class . '.PLURAL_NAME', 'Entries of words to keep together'); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function getCMSFields() |
65
|
|
|
{ |
66
|
|
|
$fields = parent::getCMSFields(); |
67
|
|
|
//do first?? |
68
|
|
|
$rightFieldDescriptions = $this->Config()->get('field_labels_right'); |
69
|
|
|
if (is_array($rightFieldDescriptions) && count($rightFieldDescriptions)) { |
70
|
|
|
foreach ($rightFieldDescriptions as $field => $desc) { |
71
|
|
|
$formField = $fields->DataFieldByName($field); |
72
|
|
|
if (! $formField) { |
73
|
|
|
$formField = $fields->DataFieldByName($field . 'ID'); |
74
|
|
|
} |
75
|
|
|
if ($formField) { |
76
|
|
|
$formField->setDescription($desc); |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
//... |
81
|
|
|
return $fields; |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|