-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAluminumPhoneNumberBlock.php
More file actions
63 lines (53 loc) · 1.36 KB
/
AluminumPhoneNumberBlock.php
File metadata and controls
63 lines (53 loc) · 1.36 KB
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
60
61
62
63
<?php
namespace Drupal\aluminum_blocks\Plugin\Block;
use Drupal\Core\Url;
/**
* Provides a 'Phone number' block.
*
* @Block(
* id = "aluminum_phone_number",
* admin_label = @Translation("Phone number"),
* )
*/
class AluminumPhoneNumberBlock extends AluminumBlockBase {
/**
* Get the phone number options.
*
* @return array
* An array of phone number options.
*/
protected function getPhoneNumberOptions() {
$options = [];
foreach (aluminum_vault_phone_numbers() as $phone_number_type => $info) {
$options[$phone_number_type] = $info['title'];
}
return $options;
}
/**
* {@inheritdoc}
*/
public function getOptions() {
return [
'phone_number_type' => [
'#type' => 'select',
'#title' => $this->t('Phone number type'),
'#description' => $this->t('Choose which phone number type to display.'),
'#options' => $this->getPhoneNumberOptions(),
'#default_value' => 'phone_number',
],
];
}
/**
* {@inheritdoc}
*/
public function build() {
$type = $this->getOptionValue('phone_number_type');
$phone_number = aluminum_vault_config('contact_info.' . $type);
$url = Url::fromUri('tel:+1 ' . $phone_number);
return [
'#theme' => 'aluminum_phone_number',
'#phone_number' => $phone_number,
'#url' => $url,
];
}
}