You are here

public function MobileNumber::prepare in Mobile Number 8

Same name and namespace in other branches
  1. 2.0.x src/Plugin/WebformElement/MobileNumber.php \Drupal\mobile_number\Plugin\WebformElement\MobileNumber::prepare()

Prepare an element to be rendered within a webform.

Parameters

array $element: An element.

\Drupal\webform\WebformSubmissionInterface $webform_submission: A webform submission. Webform submission is optional since it is not used by composite sub elements.

Overrides WebformElementBase::prepare

See also

\Drupal\webform\Element\WebformCompositeBase::processWebformComposite

File

src/Plugin/WebformElement/MobileNumber.php, line 122

Class

MobileNumber
Provides a 'mobile_number' element.

Namespace

Drupal\mobile_number\Plugin\WebformElement

Code

public function prepare(array &$element, WebformSubmissionInterface $webform_submission = NULL) {
  parent::prepare($element, $webform_submission);
  $settings = [
    'countries' => !empty($element['#countries']) ? $element['#countries'] : [],
    'placeholder' => isset($element['#mn_placeholder']) ? $element['#mn_placeholder'] : 'Phone number',
  ];
  $element += [
    '#mobile_number' => [
      'allowed_countries' => array_combine($settings['countries'], $settings['countries']),
      'verify' => MobileNumberUtilInterface::MOBILE_NUMBER_VERIFY_NONE,
      'placeholder' => isset($settings['placeholder']) ? $settings['placeholder'] : NULL,
    ],
  ];
}