public function MobileNumber::formatHtmlItem in Mobile Number 8
Same name and namespace in other branches
- 2.0.x src/Plugin/WebformElement/MobileNumber.php \Drupal\mobile_number\Plugin\WebformElement\MobileNumber::formatHtmlItem()
Format an element's value as HTML.
Parameters
array $element: An element.
\Drupal\webform\WebformSubmissionInterface $webform_submission: A webform submission.
array $options: An array of options.
Return value
array|string The element's value formatted as HTML or a render array.
Overrides WebformElementBase::formatHtmlItem
File
- src/
Plugin/ WebformElement/ MobileNumber.php, line 142
Class
- MobileNumber
- Provides a 'mobile_number' element.
Namespace
Drupal\mobile_number\Plugin\WebformElementCode
public function formatHtmlItem(array $element, WebformSubmissionInterface $webform_submission, array $options = []) {
$value = $this
->getValue($element, $webform_submission, $options);
if (empty($value['value'])) {
return '';
}
/** @var \Drupal\mobile_number\MobileNumberUtilInterface $util */
$util = \Drupal::service('mobile_number.util');
$format = $this
->getItemFormat($element);
$phoneDisplayFormat = NULL;
switch ($format) {
case 'mobile_number_international':
$phoneDisplayFormat = 1;
break;
case 'mobile_number_local':
$phoneDisplayFormat = 2;
break;
}
$as_link = !empty($element['#as_link']);
if ($mobile_number = $util
->getMobileNumber($value['value'], NULL, [])) {
if (!empty($as_link)) {
$element = [
'#type' => 'link',
'#title' => $util
->libUtil()
->format($mobile_number, $phoneDisplayFormat),
'#url' => Url::fromUri("tel:" . $util
->getCallableNumber($mobile_number)),
];
}
else {
$element = [
'#plain_text' => $util
->libUtil()
->format($mobile_number, $phoneDisplayFormat),
];
}
}
return $element;
}