Source of file DiscountCouponSiteTreeDODField.php
Size: 1,288 Bytes - Last Modified: 2021-12-23T10:40:47+00:00
/var/www/docs.ssmods.com/process/src/src/Form/DiscountCouponSiteTreeDODField.php
1234567891011121314151617181920212223242526272829303132333435363738394041 | <?php namespace Sunnysideup\EcommerceDiscountCoupon\Form; use SilverStripe\Forms\TreeMultiselectField; use SilverStripe\ORM\DataObjectInterface; class DiscountCouponSiteTreeDODField extends TreeMultiselectField { /** * @todoexplain how this works or what it does. */ public function saveInto(DataObjectInterface $record) { if ('unchanged' !== $this->value) { $items = []; $fieldName = $this->name; if ($this->value) { $items = preg_split('# *, *#', trim($this->value)); } // Allows you to modify the items on your object before save $funcName = "onChange{$fieldName}"; if ($record->hasMethod($funcName)) { $result = $record->{$funcName}($items); if (! $result) { return; } } if ($fieldName && ($record->getSchema()->hasManyComponent($record->ClassName, $fieldName) || $record->getSchema()->manyManyComponent($record->ClassName, $fieldName))) { // Set related records $record->{$fieldName}()->setByIDList($items); } else { $record->{$fieldName} = implode(',', $items); } } } } |