-
Notifications
You must be signed in to change notification settings - Fork 227
/
EditableFormField.php
executable file
·890 lines (783 loc) · 22 KB
/
EditableFormField.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
<?php
use SilverStripe\Forms\SegmentField;
/**
* Represents the base class of a editable form field
* object like {@link EditableTextField}.
*
* @package userforms
*
* @property string $Name
* @property string $Title
* @property string $Default
* @property int $Sort
* @property bool $Required
* @property string $CustomErrorMessage
* @method UserDefinedForm Parent() Parent page
* @method DataList DisplayRules() List of EditableCustomRule objects
*/
class EditableFormField extends DataObject {
/**
* Set to true to hide from class selector
*
* @config
* @var bool
*/
private static $hidden = false;
/**
* Define this field as abstract (not inherited)
*
* @config
* @var bool
*/
private static $abstract = true;
/**
* Flag this field type as non-data (e.g. literal, header, html)
*
* @config
* @var bool
*/
private static $literal = false;
/**
* Default sort order
*
* @config
* @var string
*/
private static $default_sort = '"Sort"';
/**
* A list of CSS classes that can be added
*
* @var array
*/
public static $allowed_css = array();
/**
* @config
* @var array
*/
private static $summary_fields = array(
'Title'
);
/**
* @config
* @var array
*/
private static $db = array(
"Name" => "Varchar",
"Title" => "Varchar(255)",
"Default" => "Varchar(255)",
"Sort" => "Int",
"Required" => "Boolean",
"CustomErrorMessage" => "Varchar(255)",
"CustomRules" => "Text", // @deprecated from 2.0
"CustomSettings" => "Text", // @deprecated from 2.0
"Migrated" => "Boolean", // set to true when migrated
"ExtraClass" => "Text", // from CustomSettings
"RightTitle" => "Varchar(255)", // from CustomSettings
"ShowOnLoad" => "Boolean(1)", // from CustomSettings
);
private static $defaults = array(
'ShowOnLoad' => true,
);
/**
* @config
* @var array
*/
private static $has_one = array(
"Parent" => "UserDefinedForm",
);
/**
* Built in extensions required
*
* @config
* @var array
*/
private static $extensions = array(
"Versioned('Stage', 'Live')"
);
/**
* @config
* @var array
*/
private static $has_many = array(
"DisplayRules" => "EditableCustomRule.Parent" // from CustomRules
);
/**
* @var bool
*/
protected $readonly;
/**
* Set the visibility of an individual form field
*
* @param bool
*/
public function setReadonly($readonly = true) {
$this->readonly = $readonly;
}
/**
* Returns whether this field is readonly
*
* @return bool
*/
private function isReadonly() {
return $this->readonly;
}
/**
* @return FieldList
*/
public function getCMSFields() {
$fields = new FieldList(new TabSet('Root'));
// Main tab
$fields->addFieldsToTab(
'Root.Main',
array(
ReadonlyField::create(
'Type',
_t('EditableFormField.TYPE', 'Type'),
$this->i18n_singular_name()
),
LiteralField::create(
'MergeField',
_t(
'EditableFormField.MERGEFIELDNAME',
'<div class="field readonly">' .
'<label class="left">Merge field</label>' .
'<div class="middleColumn">' .
'<span class="readonly">$' . $this->Name . '</span>' .
'</div>' .
'</div>'
)
),
TextField::create('Title'),
TextField::create('Default', _t('EditableFormField.DEFAULT', 'Default value')),
TextField::create('RightTitle', _t('EditableFormField.RIGHTTITLE', 'Right title')),
SegmentField::create('Name')->setModifiers(array(
UnderscoreSegmentFieldModifier::create()->setDefault('FieldName'),
DisambiguationSegmentFieldModifier::create(),
))->setPreview($this->Name)
)
);
// Custom settings
if (!empty(self::$allowed_css)) {
$cssList = array();
foreach(self::$allowed_css as $k => $v) {
if (!is_array($v)) {
$cssList[$k]=$v;
} elseif ($k === $this->ClassName) {
$cssList = array_merge($cssList, $v);
}
}
$fields->addFieldToTab('Root.Main',
DropdownField::create(
'ExtraClass',
_t('EditableFormField.EXTRACLASS_TITLE', 'Extra Styling/Layout'),
$cssList
)->setDescription(_t(
'EditableFormField.EXTRACLASS_SELECT',
'Select from the list of allowed styles'
))
);
} else {
$fields->addFieldToTab('Root.Main',
TextField::create(
'ExtraClass',
_t('EditableFormField.EXTRACLASS_Title', 'Extra CSS classes')
)->setDescription(_t(
'EditableFormField.EXTRACLASS_MULTIPLE',
'Separate each CSS class with a single space'
))
);
}
// Validation
$validationFields = $this->getFieldValidationOptions();
if($validationFields && $validationFields->count()) {
$fields->addFieldsToTab('Root.Validation', $validationFields);
}
// Add display rule fields
$displayFields = $this->getDisplayRuleFields();
if($displayFields && $displayFields->count()) {
$fields->addFieldsToTab('Root.DisplayRules', $displayFields);
}
$this->extend('updateCMSFields', $fields);
return $fields;
}
/**
* Return fields to display on the 'Display Rules' tab
*
* @return FieldList
*/
protected function getDisplayRuleFields() {
// Check display rules
if($this->Required) {
return new FieldList(
LabelField::create(_t(
'EditableFormField.DISPLAY_RULES_DISABLED',
'Display rules are not enabled for required fields. ' .
'Please uncheck "Is this field Required?" under "Validation" to re-enable.'
))->addExtraClass('message warning')
);
}
$self = $this;
$allowedClasses = array_keys($this->getEditableFieldClasses(false));
$editableColumns = new GridFieldEditableColumns();
$editableColumns->setDisplayFields(array(
'Display' => '',
'ConditionFieldID' => function($record, $column, $grid) use ($allowedClasses, $self) {
return DropdownField::create(
$column,
'',
EditableFormField::get()
->filter(array(
'ParentID' => $self->ParentID,
'ClassName' => $allowedClasses
))
->exclude(array(
'ID' => $self->ID
))
->map('ID', 'Title')
);
},
'ConditionOption' => function($record, $column, $grid) {
$options = Config::inst()->get('EditableCustomRule', 'condition_options');
return DropdownField::create($column, '', $options);
},
'FieldValue' => function($record, $column, $grid) {
return TextField::create($column);
},
'ParentID' => function($record, $column, $grid) use ($self) {
return HiddenField::create($column, '', $self->ID);
}
));
// Custom rules
$customRulesConfig = GridFieldConfig::create()
->addComponents(
$editableColumns,
new GridFieldButtonRow(),
new GridFieldToolbarHeader(),
new GridFieldAddNewInlineButton(),
new GridFieldDeleteAction()
);
return new FieldList(
CheckboxField::create('ShowOnLoad')
->setDescription(_t(
'EditableFormField.SHOWONLOAD',
'Initial visibility before processing these rules'
)),
GridField::create(
'DisplayRules',
_t('EditableFormField.CUSTOMRULES', 'Custom Rules'),
$this->DisplayRules(),
$customRulesConfig
)
);
}
public function onBeforeWrite() {
parent::onBeforeWrite();
// Set a field name.
if(!$this->Name) {
// New random name
$this->Name = $this->generateName();
} elseif($this->Name === 'Field') {
throw new ValidationException('Field name cannot be "Field"');
}
if(!$this->Sort && $this->ParentID) {
$parentID = $this->ParentID;
$this->Sort = EditableFormField::get()
->filter('ParentID', $parentID)
->max('Sort') + 1;
}
}
/**
* Generate a new non-conflicting Name value
*
* @return string
*/
protected function generateName() {
do {
// Generate a new random name after this class
$class = get_class($this);
$entropy = substr(sha1(uniqid()), 0, 5);
$name = "{$class}_{$entropy}";
// Check if it conflicts
$exists = EditableFormField::get()->filter('Name', $name)->count() > 0;
} while($exists);
return $name;
}
/**
* Flag indicating that this field will set its own error message via data-msg='' attributes
*
* @return bool
*/
public function getSetsOwnError() {
return false;
}
/**
* Return whether a user can delete this form field
* based on whether they can edit the page
*
* @param Member $member
* @return bool
*/
public function canDelete($member = null) {
return $this->canEdit($member);
}
/**
* Return whether a user can edit this form field
* based on whether they can edit the page
*
* @param Member $member
* @return bool
*/
public function canEdit($member = null) {
$parent = $this->Parent();
if($parent && $parent->exists()) {
return $parent->canEdit($member) && !$this->isReadonly();
}
// Fallback to secure admin permissions
return parent::canEdit($member);
}
/**
* Return whether a user can view this form field
* based on whether they can view the page, regardless of the ReadOnly status of the field
*
* @param Member $member
* @return bool
*/
public function canView($member = null) {
$parent = $this->Parent();
if($parent && $parent->exists()) {
return $parent->canView($member);
}
return true;
}
/**
* Return whether a user can create an object of this type
*
* @param Member $member
* @param array $context Virtual parameter to allow context to be passed in to check
* @return bool
*/
public function canCreate($member = null) {
// Check parent page
$parent = $this->getCanCreateContext(func_get_args());
if($parent) {
return $parent->canEdit($member);
}
// Fall back to secure admin permissions
return parent::canCreate($member);
}
/**
* Helper method to check the parent for this object
*
* @param array $args List of arguments passed to canCreate
* @return SiteTree Parent page instance
*/
protected function getCanCreateContext($args) {
// Inspect second parameter to canCreate for a 'Parent' context
if(isset($args[1]['Parent'])) {
return $args[1]['Parent'];
}
// Hack in currently edited page if context is missing
if(Controller::has_curr() && Controller::curr() instanceof CMSMain) {
return Controller::curr()->currentPage();
}
// No page being edited
return null;
}
/**
* Check if can publish
*
* @param Member $member
* @return bool
*/
public function canPublish($member = null) {
return $this->canEdit($member);
}
/**
* Check if can unpublish
*
* @param Member $member
* @return bool
*/
public function canUnpublish($member = null) {
return $this->canDelete($member);
}
/**
* Publish this Form Field to the live site
*
* Wrapper for the {@link Versioned} publish function
*/
public function doPublish($fromStage, $toStage, $createNewVersion = false) {
$this->publish($fromStage, $toStage, $createNewVersion);
// Don't forget to publish the related custom rules...
foreach ($this->DisplayRules() as $rule) {
$rule->doPublish($fromStage, $toStage, $createNewVersion);
}
}
/**
* Delete this field from a given stage
*
* Wrapper for the {@link Versioned} deleteFromStage function
*/
public function doDeleteFromStage($stage) {
// Remove custom rules in this stage
$rules = Versioned::get_by_stage('EditableCustomRule', $stage)
->filter('ParentID', $this->ID);
foreach ($rules as $rule) {
$rule->deleteFromStage($stage);
}
// Remove record
$this->deleteFromStage($stage);
}
/**
* checks wether record is new, copied from Sitetree
*/
function isNew() {
if(empty($this->ID)) return true;
if(is_numeric($this->ID)) return false;
return stripos($this->ID, 'new') === 0;
}
/**
* checks if records is changed on stage
* @return boolean
*/
public function getIsModifiedOnStage() {
// new unsaved fields could be never be published
if($this->isNew()) return false;
$stageVersion = Versioned::get_versionnumber_by_stage('EditableFormField', 'Stage', $this->ID);
$liveVersion = Versioned::get_versionnumber_by_stage('EditableFormField', 'Live', $this->ID);
return ($stageVersion && $stageVersion != $liveVersion);
}
/**
* @deprecated since version 4.0
*/
public function getSettings() {
Deprecation::notice('4.0', 'getSettings is deprecated');
return (!empty($this->CustomSettings)) ? unserialize($this->CustomSettings) : array();
}
/**
* @deprecated since version 4.0
*/
public function setSettings($settings = array()) {
Deprecation::notice('4.0', 'setSettings is deprecated');
$this->CustomSettings = serialize($settings);
}
/**
* @deprecated since version 4.0
*/
public function setSetting($key, $value) {
Deprecation::notice('4.0', "setSetting({$key}) is deprecated");
$settings = $this->getSettings();
$settings[$key] = $value;
$this->setSettings($settings);
}
/**
* Set the allowed css classes for the extraClass custom setting
*
* @param array The permissible CSS classes to add
*/
public function setAllowedCss(array $allowed) {
if (is_array($allowed)) {
foreach ($allowed as $k => $v) {
self::$allowed_css[$k] = (!is_null($v)) ? $v : $k;
}
}
}
/**
* @deprecated since version 4.0
*/
public function getSetting($setting) {
Deprecation::notice("4.0", "getSetting({$setting}) is deprecated");
$settings = $this->getSettings();
if(isset($settings) && count($settings) > 0) {
if(isset($settings[$setting])) {
return $settings[$setting];
}
}
return '';
}
/**
* Get the path to the icon for this field type, relative to the site root.
*
* @return string
*/
public function getIcon() {
return USERFORMS_DIR . '/images/' . strtolower($this->class) . '.png';
}
/**
* Return whether or not this field has addable options
* such as a dropdown field or radio set
*
* @return bool
*/
public function getHasAddableOptions() {
return false;
}
/**
* Return whether or not this field needs to show the extra
* options dropdown list
*
* @return bool
*/
public function showExtraOptions() {
return true;
}
/**
* Returns the Title for rendering in the front-end (with XML values escaped)
*
* @return string
*/
public function getEscapedTitle() {
return Convert::raw2xml($this->Title);
}
/**
* Find the numeric indicator (1.1.2) that represents it's nesting value
*
* Only useful for fields attached to a current page, and that contain other fields such as pages
* or groups
*
* @return string
*/
public function getFieldNumber() {
// Check if exists
if(!$this->exists()) {
return null;
}
// Check parent
$form = $this->Parent();
if(!$form || !$form->exists() || !($fields = $form->Fields())) {
return null;
}
$prior = 0; // Number of prior group at this level
$stack = array(); // Current stack of nested groups, where the top level = the page
foreach($fields->map('ID', 'ClassName') as $id => $className) {
if($className === 'EditableFormStep') {
$priorPage = empty($stack) ? $prior : $stack[0];
$stack = array($priorPage + 1);
$prior = 0;
} elseif($className === 'EditableFieldGroup') {
$stack[] = $prior + 1;
$prior = 0;
} elseif($className === 'EditableFieldGroupEnd') {
$prior = array_pop($stack);
}
if($id == $this->ID) {
return implode('.', $stack);
}
}
return null;
}
public function getCMSTitle() {
return $this->i18n_singular_name() . ' (' . $this->Title . ')';
}
/**
* @deprecated since version 4.0
*/
public function getFieldName($field = false) {
Deprecation::notice('4.0', "getFieldName({$field}) is deprecated");
return ($field) ? "Fields[".$this->ID."][".$field."]" : "Fields[".$this->ID."]";
}
/**
* @deprecated since version 4.0
*/
public function getSettingName($field) {
Deprecation::notice('4.0', "getSettingName({$field}) is deprecated");
$name = $this->getFieldName('CustomSettings');
return $name . '[' . $field .']';
}
/**
* Append custom validation fields to the default 'Validation'
* section in the editable options view
*
* @return FieldList
*/
public function getFieldValidationOptions() {
$fields = new FieldList(
CheckboxField::create('Required', _t('EditableFormField.REQUIRED', 'Is this field Required?'))
->setDescription(_t('EditableFormField.REQUIRED_DESCRIPTION', 'Please note that conditional fields can\'t be required')),
TextField::create('CustomErrorMessage', _t('EditableFormField.CUSTOMERROR','Custom Error Message'))
);
$this->extend('updateFieldValidationOptions', $fields);
return $fields;
}
/**
* Return a FormField to appear on the front end. Implement on
* your subclass.
*
* @return FormField
*/
public function getFormField() {
user_error("Please implement a getFormField() on your EditableFormClass ". $this->ClassName, E_USER_ERROR);
}
/**
* Updates a formfield with extensions
*
* @param FormField $field
*/
public function doUpdateFormField($field) {
$this->extend('beforeUpdateFormField', $field);
$this->updateFormField($field);
$this->extend('afterUpdateFormField', $field);
}
/**
* Updates a formfield with the additional metadata specified by this field
*
* @param FormField $field
*/
protected function updateFormField($field) {
// set the error / formatting messages
$field->setCustomValidationMessage($this->getErrorMessage()->RAW());
// set the right title on this field
if($this->RightTitle) {
// Since this field expects raw html, safely escape the user data prior
$field->setRightTitle(Convert::raw2xml($this->RightTitle));
}
// if this field is required add some
if($this->Required) {
// Required validation can conflict so add the Required validation messages as input attributes
$errorMessage = $this->getErrorMessage()->HTML();
$field->addExtraClass('requiredField');
$field->setAttribute('data-rule-required', 'true');
$field->setAttribute('data-msg-required', $errorMessage);
if($identifier = UserDefinedForm::config()->required_identifier) {
$title = $field->Title() . " <span class='required-identifier'>". $identifier . "</span>";
$field->setTitle($title);
}
}
// if this field has an extra class
if($this->ExtraClass) {
$field->addExtraClass($this->ExtraClass);
}
}
/**
* Return the instance of the submission field class
*
* @return SubmittedFormField
*/
public function getSubmittedFormField() {
return new SubmittedFormField();
}
/**
* Show this form field (and its related value) in the reports and in emails.
*
* @return bool
*/
public function showInReports() {
return true;
}
/**
* Return the error message for this field. Either uses the custom
* one (if provided) or the default SilverStripe message
*
* @return Varchar
*/
public function getErrorMessage() {
$title = strip_tags("'". ($this->Title ? $this->Title : $this->Name) . "'");
$standard = sprintf(_t('Form.FIELDISREQUIRED', '%s is required').'.', $title);
// only use CustomErrorMessage if it has a non empty value
$errorMessage = (!empty($this->CustomErrorMessage)) ? $this->CustomErrorMessage : $standard;
return DBField::create_field('Varchar', $errorMessage);
}
/**
* Invoked by UserFormUpgradeService to migrate settings specific to this field from CustomSettings
* to the field proper
*
* @param array $data Unserialised data
*/
public function migrateSettings($data) {
// Map 'Show' / 'Hide' to boolean
if(isset($data['ShowOnLoad'])) {
$this->ShowOnLoad = $data['ShowOnLoad'] === '' || ($data['ShowOnLoad'] && $data['ShowOnLoad'] !== 'Hide');
unset($data['ShowOnLoad']);
}
// Migrate all other settings
foreach($data as $key => $value) {
if($this->hasField($key)) {
$this->setField($key, $value);
}
}
}
/**
* Get the formfield to use when editing this inline in gridfield
*
* @param string $column name of column
* @param array $fieldClasses List of allowed classnames if this formfield has a selectable class
* @return FormField
*/
public function getInlineClassnameField($column, $fieldClasses) {
return DropdownField::create($column, false, $fieldClasses);
}
/**
* Get the formfield to use when editing the title inline
*
* @param string $column
* @return FormField
*/
public function getInlineTitleField($column) {
return TextField::create($column, false)
->setAttribute('placeholder', _t('EditableFormField.TITLE', 'Title'))
->setAttribute('data-placeholder', _t('EditableFormField.TITLE', 'Title'));
}
/**
* Get the JS expression for selecting the holder for this field
*
* @return string
*/
public function getSelectorHolder() {
return "$(\"#{$this->Name}\")";
}
/**
* Gets the JS expression for selecting the value for this field
*
* @param EditableCustomRule $rule Custom rule this selector will be used with
* @param bool $forOnLoad Set to true if this will be invoked on load
*/
public function getSelectorField(EditableCustomRule $rule, $forOnLoad = false) {
return "$(\"input[name='{$this->Name}']\")";
}
/**
* Get the list of classes that can be selected and used as data-values
*
* @param $includeLiterals Set to false to exclude non-data fields
* @return array
*/
public function getEditableFieldClasses($includeLiterals = true) {
$classes = ClassInfo::getValidSubClasses('EditableFormField');
// Remove classes we don't want to display in the dropdown.
$editableFieldClasses = array();
foreach ($classes as $class) {
// Skip abstract / hidden classes
if(Config::inst()->get($class, 'abstract', Config::UNINHERITED) || Config::inst()->get($class, 'hidden')
) {
continue;
}
if(!$includeLiterals && Config::inst()->get($class, 'literal')) {
continue;
}
$singleton = singleton($class);
if(!$singleton->canCreate()) {
continue;
}
$editableFieldClasses[$class] = $singleton->i18n_singular_name();
}
asort($editableFieldClasses);
return $editableFieldClasses;
}
/**
* @return EditableFormFieldValidator
*/
public function getCMSValidator() {
return EditableFormFieldValidator::create()
->setRecord($this);
}
/**
* Determine effective display rules for this field.
*
* @return SS_List
*/
public function EffectiveDisplayRules() {
if($this->Required) {
return new ArrayList();
}
return $this->DisplayRules();
}
}