- Issue created by @gidel
- Merge request !24Issue 3511592 - Add attributes of provided element to the int_phone form field. → (Open) created by Unnamed author
When the module process the international phone to create the int_phone
form element, all attributes are defined by the module and it's impossible to use options or attributes provided by the 'phone_international' field type.
For example, if I want to set an attribute data-number-type
to my field :
$form['phone'] = [
'#type' => 'phone_international',
'#title' => $this->t('International Phone'),
'#exclude_countries' => ['GB', 'BH', 'US'],
'#preferred_countries' => ['FR', 'IT'],
'#geolocation' => 1,
'#attributes' => [
'data-number-type' => 'fixed_line',
],
];
My attribute data-number-type
will be overwritten by the processInternationalPhone()
method that set #attributes
with predefined values.
$element['int_phone'] = [
'#type' => 'tel',
'#default_value' => $element['#default_value'],
'#attributes' => [
'placeholder' => $element['#placeholder'] ?? '',
'class' => ['phone_international-number'],
'data-country' => (int) $element['#geolocation'] === 1 ? 'auto' : $element['#country'],
'data-geo' => (int) $element['#geolocation'],
'data-preferred' => $element['#preferred_countries'] ? implode("-", $element['#preferred_countries']) : [],
],
'#theme_wrappers' => [],
'#size' => 30,
'#maxlength' => 128,
];
When creating the int_phone
form element, add provided attributes by the original form element in the #attributes
array.
Active
3.3
Code