Last active
June 14, 2017 04:43
-
-
Save zanderwar/d14f9172c1d7af785a2ca2d76eb95fc5 to your computer and use it in GitHub Desktop.
Populates a SilverStripe Form subclass with DataObject values
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class MyForm extends Form | |
{ | |
/** | |
* @param Customer $customer | |
* @return $this | |
*/ | |
public function setObject(DataObject $object) | |
{ | |
$fields = self::Fields(); | |
/** @var FormField $field */ | |
foreach ($fields as $field) { | |
$value = $field->getName(); | |
if ($object->{$value}) { | |
$field->setValue($object->{$value}); | |
} | |
} | |
return $this; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment