You are here

protected function WebformTelephone::formatHtmlItemValue in Webform 6.x

Same name and namespace in other branches
  1. 8.5 src/Plugin/WebformElement/WebformTelephone.php \Drupal\webform\Plugin\WebformElement\WebformTelephone::formatHtmlItemValue()

Format composite element value into lines of text.

Parameters

array $element: An element.

\Drupal\webform\WebformSubmissionInterface $webform_submission: A webform submission.

array $options: An array of options.

Return value

array Composite element values converted into lines of html.

Overrides WebformCompositeBase::formatHtmlItemValue

File

src/Plugin/WebformElement/WebformTelephone.php, line 51

Class

WebformTelephone
Provides a 'telephone' (composite) element.

Namespace

Drupal\webform\Plugin\WebformElement

Code

protected function formatHtmlItemValue(array $element, WebformSubmissionInterface $webform_submission, array $options = []) {
  $value = $this
    ->getValue($element, $webform_submission, $options);
  $t_args = [
    ':tel' => 'tel:' . $value['phone'],
    '@tel' => $value['phone'],
    '@ext' => $value['ext'],
    '@type' => $value['type'],
  ];
  if ($value['ext'] && $value['type']) {
    $telephone = $this
      ->t('<b>@type:</b> <a href=":tel">@tel</a> x@ext', $t_args);
  }
  elseif ($value['ext']) {
    $telephone = $this
      ->t('<a href=":tel">@tel</a> x@ext', $t_args);
  }
  elseif ($value['type']) {
    $telephone = $this
      ->t('<b>@type:</b> <a href=":tel">@tel</a>', $t_args);
  }
  else {
    $telephone = $this
      ->t('<a href=":tel">@tel</a>', $t_args);
  }
  return [
    'telephone' => [
      '#markup' => $telephone,
    ],
  ];
}