/
PhoneLink.php
59 lines (48 loc) · 1.49 KB
/
PhoneLink.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php declare(strict_types=1);
namespace SilverStripe\LinkField\Models;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\CompositeValidator;
use SilverStripe\Forms\RequiredFields;
/**
* A link to a phone number
*/
class PhoneLink extends Link
{
private static string $table_name = 'LinkField_PhoneLink';
private static array $db = [
'Phone' => 'Varchar(255)',
];
private static int $menu_priority = 40;
private static $icon = 'font-icon-mobile';
public function getCMSFields(): FieldList
{
$this->beforeUpdateCMSFields(function (FieldList $fields) {
$field = $fields->dataFieldByName('Phone');
$field->setTitle(_t(__CLASS__ . '.PHONE_FIELD', 'Phone'));
$fields->removeByName('OpenInNew');
});
return parent::getCMSFields();
}
public function getDescription(): string
{
return $this->Phone ?: '';
}
public function getURL(): string
{
return $this->Phone ? sprintf('tel:%s', $this->Phone) : '';
}
/**
* The title that will be displayed in the dropdown
* for selecting the link type to create.
*/
public function getMenuTitle(): string
{
return _t(__CLASS__ . '.LINKLABEL', 'Phone number');
}
public function getCMSCompositeValidator(): CompositeValidator
{
$validator = parent::getCMSCompositeValidator();
$validator->addValidator(RequiredFields::create(['Phone']));
return $validator;
}
}