dynamic / silverstripe-elemental-customer-service
1
<?php
2

3
namespace Dynamic\Elements\CustomerService\Elements;
4

5
use DNADesign\Elemental\Models\BaseElement;
6
use SilverStripe\Forms\EmailField;
7
use SilverStripe\Forms\FieldList;
8
use SilverStripe\ORM\FieldType\DBField;
9

10
/**
11
 * Class ElementCustomerService
12
 * @package Dynamic\Elements\CustomerService\Elements
13
 *
14
 * @property string $Title
15
 * @property string $Website
16
 * @property string $Phone
17
 * @property string $Email
18
 * @property string $Fax
19
 */
20
class ElementCustomerService extends BaseElement
21
{
22
    /**
23
     * @var string
24
     */
25
    private static $icon = 'font-icon-info-circled';
26

27
    /**
28
     * @var string
29
     */
30
    private static $table_name = 'ElementCustomerService';
31

32
    /**
33
     * @var array
34
     */
35
    private static $db = [
36
        'LocationName' => 'Varchar(255)',
37
        'Website' => 'Varchar(255)',
38
        'Phone' => 'Varchar(40)',
39
        'Email' => 'Varchar(255)',
40
        'Fax' => 'Varchar(45)',
41
    ];
42

43
    /**
44
     * @param bool $includerelations
45
     * @return array
46
     */
47 2
    public function fieldLabels($includerelations = true)
48
    {
49 2
        $labels = parent::fieldLabels($includerelations);
50

51 2
        $labels['LocationName'] = _t(__CLASS__.'.LocationNameLabel', 'Location Name');
52 2
        $labels['Website'] = _t(__CLASS__ . '.WebsiteLabel', 'Website');
53 2
        $labels['Phone'] = _t(__CLASS__ . '.PhoneLabel', 'Phone');
54 2
        $labels['Email'] = _t(__CLASS__ . '.EmailLabel', 'Email');
55 2
        $labels['Fax'] = _t(__CLASS__ . '.FaxLabel', 'Fax');
56

57 2
        return $labels;
58
    }
59

60
    /**
61
     * @return FieldList
62
     */
63
    public function getCMSFields()
64
    {
65 2
        $this->beforeUpdateCMSFields(function (FieldList $fields) {
66 2
            if ($website = $fields->dataFieldByName('Website')) {
67 2
                $website->setAttribute('placeholder', 'http://');
68
            }
69 2
            $fields->replaceField(
70 2
                'Email',
71 2
                EmailField::create('Email')
72 2
                    ->setTitle($this->fieldLabel('Email'))
73
            );
74 2
        });
75

76 2
        return parent::getCMSFields();
77
    }
78

79
    /**
80
     * @return DBHTMLText
81
     */
82 0
    public function getSummary()
83
    {
84 0
        return DBField::create_field('HTMLText', $this->getFullAddress())->Summary(20);
85
    }
86

87
    /**
88
     * @return array
89
     */
90 0
    protected function provideBlockSchema()
91
    {
92 0
        $blockSchema = parent::provideBlockSchema();
93 0
        $blockSchema['content'] = $this->getSummary();
94 0
        return $blockSchema;
95
    }
96

97
    /**
98
     * @return string
99
     */
100 2
    public function getType()
101
    {
102 2
        return _t(__CLASS__.'.BlockType', 'Customer Service');
103
    }
104
}

Read our documentation on viewing source code .

Loading