You are here

protected function WebformTelephone::formatTextItemValue in Webform 8.5

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

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 text.

Overrides WebformCompositeBase::formatTextItemValue

File

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

Class

WebformTelephone
Provides a 'telephone' (composite) element.

Namespace

Drupal\webform\Plugin\WebformElement

Code

protected function formatTextItemValue(array $element, WebformSubmissionInterface $webform_submission, array $options = []) {
  $value = $this
    ->getValue($element, $webform_submission, $options);
  $t_args = [
    '@tel' => $value['phone'],
    '@ext' => $value['ext'],
    '@type' => $value['type'],
  ];
  if ($value['ext'] && $value['type']) {
    return [
      'telephone' => $this
        ->t('@type: @tel x@ext', $t_args),
    ];
  }
  elseif ($value['ext']) {
    return [
      'telephone' => $this
        ->t('@tel x@ext', $t_args),
    ];
  }
  elseif ($value['type']) {
    return [
      'telephone' => $this
        ->t('@type: @tel', $t_args),
    ];
  }
  else {
    return [
      'telephone' => $this
        ->t('@tel', $t_args),
    ];
  }
}