| Conditions | 6 |
| Paths | 5 |
| Total Lines | 33 |
| Code Lines | 17 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 36 | public function php($data) |
||
| 37 | { |
||
| 38 | if (!parent::php($data)) { |
||
| 39 | return false; |
||
| 40 | } |
||
| 41 | |||
| 42 | // Skip unsaved records |
||
| 43 | if (!$this->record || !$this->record->exists()) { |
||
| 44 | return true; |
||
| 45 | } |
||
| 46 | |||
| 47 | // Skip validation if not required |
||
| 48 | if (empty($data['Required'])) { |
||
| 49 | return; |
||
| 50 | } |
||
| 51 | |||
| 52 | // Skip validation if no rules |
||
| 53 | $count = EditableCustomRule::get()->filter('ParentID', $this->record->ID)->count(); |
||
| 54 | if ($count == 0) { |
||
| 55 | return true; |
||
| 56 | } |
||
| 57 | |||
| 58 | // Both required = true and rules > 0 should error |
||
| 59 | $this->validationError( |
||
| 60 | 'Required_Error', |
||
| 61 | _t( |
||
| 62 | __CLASS__.'.REQUIRED_ERROR', |
||
| 63 | 'Form fields cannot be required and have conditional display rules.' |
||
| 64 | ), |
||
| 65 | 'error' |
||
| 66 | ); |
||
| 67 | return false; |
||
| 68 | } |
||
| 69 | } |
||
| 70 |