-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathAddress.php
More file actions
87 lines (79 loc) · 2.12 KB
/
Address.php
File metadata and controls
87 lines (79 loc) · 2.12 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
/**
* Copyright © All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Flekto\Postcode\Block\Adminhtml\Form\Field;
use Magento\Framework\View\Element\Html\Select;
class Address extends Select
{
private $scopeConfig;
public function __construct(
\Magento\Framework\View\Element\Context $context,
array $data = []
) {
$this->scopeConfig = $context->getScopeConfig();
parent::__construct($context,$data);
}
/**
* Set "name" for <select> element
*
* @param string $value
* @return $this
*/
public function setInputName($value)
{
return $this->setName($value);
}
/**
* Set "id" for <select> element
*
* @param $value
* @return $this
*/
public function setInputId($value)
{
return $this->setId($value);
}
/**
* Render block HTML
*
* @return string
*/
public function _toHtml(): string
{
if (!$this->getOptions()) {
$this->setOptions($this->getSourceOptions());
}
return parent::_toHtml();
}
private function getSourceOptions(): array
{
$extrafields = false;
if($this->scopeConfig->getValue('postcodenl_api/general/address_fields_extra')) $extrafields = explode("\n", $this->scopeConfig->getValue('postcodenl_api/general/address_fields_extra'));
$defaultFields = [
'firstname',
'lastname',
'postcode_nl',
'street',
'postcode',
'city',
'country_id',
'region_id',
'telephone',
'company',
'vat_id'
];
$ar = [];
foreach($defaultFields as $field){
$ar[] = ['label' => str_replace('_', ' ', str_replace('_id', '', ucfirst($field))), 'value' => $field];
}
if($extrafields){
foreach($extrafields as $field){
$ar[] = ['label' => str_replace('_', ' ', str_replace('_id', '', ucfirst($field))), 'value' => $field];
}
}
return $ar;
}
}