Issues (5)

src/extensions/SiteConfigExtension.php (4 issues)

1
<?php
2
3
namespace SilverCommerce\Settings\Extensions;
4
5
use SilverStripe\i18n\i18n;
6
use SilverStripe\Assets\Image;
7
use SilverStripe\Forms\FieldList;
8
use SilverStripe\Forms\TextField;
9
use SilverStripe\ORM\DataExtension;
10
use SilverStripe\Forms\TextareaField;
11
use SilverStripe\Forms\DropdownField;
12
use SilverStripe\Forms\CheckboxField;
13
use SilverStripe\Forms\ToggleCompositeField;
14
use SilverStripe\AssetAdmin\Forms\UploadField;
0 ignored issues
show
The type SilverStripe\AssetAdmin\Forms\UploadField was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
15
16
class SiteConfigExtension extends DataExtension
17
{
18
    private static $db = [
0 ignored issues
show
The private property $db is not used, and could be removed.
Loading history...
19
        "SiteLocale" => "Varchar(5)",
20
        "ContactPhone" => "Varchar(25)",
21
        "ContactEmail" => "Varchar(255)",
22
        "ContactAddress" => "Text",
23
        "ShowPriceAndTax" => "Boolean",
24
        "ShowPriceTaxString" => "Boolean"
25
    ];
26
27
    private static $has_one = [
0 ignored issues
show
The private property $has_one is not used, and could be removed.
Loading history...
28
        "CardLogos" => Image::class
29
    ];
30
31
    private static $casting = [
0 ignored issues
show
The private property $casting is not used, and could be removed.
Loading history...
32
        "InlineContactAddress" => "Text",
33
        "TrimmedContactPhone" => "Varchar(15)"
34
    ];
35
36
    public function getInlineContactAddress()
37
    {
38
        return trim(preg_replace('/\s\s+/', ', ', $this->owner->ContactAddress));
39
    }
40
41
    public function getTrimmedContactPhone()
42
    {
43
        return trim(str_replace(" ","",$this->owner->ContactPhone));
44
    }
45
46
    public function updateCMSFields(FieldList $fields)
47
    {
48
        $fields->removeByName("ContactPhone");
49
        $fields->removeByName("ContactEmail");
50
        $fields->removeByName("ContactAddress");
51
        $fields->removeByName("SiteLocale");
52
        $fields->removeByName("ShowPriceAndTax");
53
        $fields->removeByName("ShowPriceTaxString");
54
55
        $fields->addFieldsToTab(
56
            "Root.Main",
57
            [
58
                DropdownField::create(
59
                    "SiteLocale",
60
                    $this->owner->fieldLabel("SiteLocale"),
61
                    i18n::getSources()->getKnownLocales()
62
                ),
63
                TextField::create(
64
                    "ContactPhone",
65
                    $this->owner->fieldLabel("ContactPhone")
66
                ),
67
                TextField::create(
68
                    "ContactEmail",
69
                    $this->owner->fieldLabel("ContactEmail")
70
                ),
71
                TextareaField::create(
72
                    "ContactAddress",
73
                    $this->owner->fieldLabel("ContactAddress")
74
                )
75
            ]
76
        );
77
78
        $fields->addFieldToTab(
79
            "Root.Shop",
80
            ToggleCompositeField::create(
81
                'MiscSettings',
82
                _t("Settings.MiscSettings", "Misc Settings"),
83
                [
84
                    CheckboxField::create("ShowPriceAndTax")
85
                        ->setDescription(_t(
86
                            "SilverCommerce\Settings.ShowPriceAndTaxDescription",
87
                            "Show product prices including tax"
88
                        )),
89
                    CheckboxField::create("ShowPriceTaxString")
90
                        ->setDescription(_t(
91
                            "SilverCommerce\Settings.ShowProductTaxStringDescription",
92
                            "Show 'inc/exc TAX' after price"
93
                        )),
94
                    UploadField::create(
95
                        "CardLogos",
96
                        $this->owner->fieldLabel("CardLogos")
97
                    )
98
                ]
99
            )
100
        );
101
    }
102
103
    public function onBeforeWrite()
104
    {
105
        if (empty($this->owner->SiteLocale)) {
106
            $this->owner->SiteLocale = i18n::config()->default_locale;
107
        }
108
    }
109
}