How to populate the phone_international field type programmatically

Created on 12 September 2023, over 1 year ago

How to populate the phone_international field type like country flag as well programmatically in Drupal9.

Right now it is setting the country flag what we set in the widget in the manage form display as default. How can we set the country flag as well to phone_international field type.

📌 Task
Status

Needs work

Version

3.3

Component

Documentation

Created by

🇮🇳India kanchamk

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @kanchamk
  • 🇲🇩Moldova nick.murza Moldova

    Hi, here is my example

    $countries = array_keys($this->countryManager->getList());
    // Trim the required countries from excluded countries.
    $excluded_countries = array_diff($countries, ['MD', 'RO']);
    $form['blah']['contact_info']['phone_number'] = [
    '#type' => 'phone_international',
    '#title' => $this->t('Phone number'),
    '#country' => 'MD',
    '#geolocation' => TRUE,
    '#exclude_countries' => $excluded_countries,
    '#size' => 12,
    '#maxlength' => 12,
    '#countries' => ['MD', 'RO'],
    '#placeholder' => '0XXYYYYYY',
    ];

  • Status changed to Closed: duplicate 4 days ago
  • 🇵🇹Portugal saidatom Lisbon
Production build 0.71.5 2024