1 <?php
2 3 4 5 6
7 class YMLSiteConfig extends SiteConfigDecorator {
8 function () {
9 return array(
10 'db' => array(
11 'YMLCurrency' => 'Varchar',
12 'YMLRate' => 'Varchar',
13 'YMLName' => 'Varchar',
14 'YMLCompany' => 'Varchar',
15 'YMLHref' => 'Varchar',
16 'YMLAvailableOnly' => 'Boolean',
17 ),
18 'defaults' => array(
19 'YMLCurrency' => 'RUR',
20 'YMLRate' => 1,
21 'YMLAvailableOnly' => 1,
22 )
23 );
24 }
25
26 public function updateCMSFields(FieldSet &$fields) {
27 $tab = SiteConfigDecorator::get_config_tab($fields, 'Catalog');
28
29 $tab->push(new DropdownField('YMLCurrency', $this->owner->fieldLabel('YMLCurrency'), array('RUR'=>'RUR', 'USD'=>'USD', 'EUR' => 'EUR')));
30 $tab->push(new TextField('YMLRate', $this->owner->fieldLabel('YMLRate'), 1));
31 $tab->push(new TextField('YMLName', $this->owner->fieldLabel('YMLName')));
32 $tab->push(new TextField('YMLCompany', $this->owner->fieldLabel('YMLCompany')));
33 $tab->push(new TextField('YMLHref', $this->owner->fieldLabel('YMLHref')));
34 $tab->push(new CheckboxField('YMLAvailableOnly', $this->owner->fieldLabel('YMLAvailableOnly')));
35
36
37 }
38
39 function onBeforeWrite() {
40 parent::onBeforeWrite();
41
42 if ($this->owner->YMLCurrency == 'RUR') {
43 $this->owner->YMLRate = 1;
44 }
45 elseif (!floatval($this->owner->YMLRate)) {
46 $this->owner->YMLRate = 'CBRF';
47 }
48
49 if (substr($this->owner->YMLHref, 0, 7) != 'http://') {
50 $this->owner->YMLHref = 'http://' . $this->owner->YMLHref;
51 }
52 }
53
54 }
55
[Raise a SilverStripe Framework issue/bug](https://github.com/silverstripe/silverstripe-framework/issues/new)
- [Raise a SilverStripe CMS issue/bug](https://github.com/silverstripe/silverstripe-cms/issues/new)
- Please use the
Silverstripe Forums to ask development related questions.
-