| Conditions | 8 |
| Paths | 11 |
| Total Lines | 27 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 11 | public function saveInto(DataObjectInterface $record) |
||
| 12 | { |
||
| 13 | if ($this->value !== 'unchanged') { |
||
| 14 | $items = array(); |
||
| 15 | |||
| 16 | $fieldName = $this->name; |
||
| 17 | |||
| 18 | if ($this->value) { |
||
| 19 | $items = preg_split("/ *, */", trim($this->value)); |
||
| 20 | } |
||
| 21 | |||
| 22 | // Allows you to modify the items on your object before save |
||
| 23 | $funcName = "onChange$fieldName"; |
||
| 24 | if ($record->hasMethod($funcName)) { |
||
| 25 | $result = $record->$funcName($items); |
||
| 26 | if (!$result) { |
||
| 27 | return; |
||
| 28 | } |
||
| 29 | } |
||
| 30 | if ($fieldName && ($record->has_many($fieldName) || $record->many_many($fieldName))) { |
||
| 31 | // Set related records |
||
| 32 | $record->$fieldName()->setByIDList($items); |
||
| 33 | } else { |
||
| 34 | $record->$fieldName = implode(',', $items); |
||
| 35 | } |
||
| 36 | } |
||
| 37 | } |
||
| 38 | } |
||
| 39 |