You are here

protected function WebformAttachmentBase::formatTextItem in Webform 6.x

Same name and namespace in other branches
  1. 8.5 modules/webform_attachment/src/Plugin/WebformElement/WebformAttachmentBase.php \Drupal\webform_attachment\Plugin\WebformElement\WebformAttachmentBase::formatTextItem()

Format an element's value as text.

Parameters

array $element: An element.

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

array $options: An array of options.

Return value

string The element's value formatted as text.

Overrides WebformElementBase::formatTextItem

See also

_webform_token_get_submission_value()

File

modules/webform_attachment/src/Plugin/WebformElement/WebformAttachmentBase.php, line 105

Class

WebformAttachmentBase
Provides a base class for 'webform_attachment' elements.

Namespace

Drupal\webform_attachment\Plugin\WebformElement

Code

protected function formatTextItem(array $element, WebformSubmissionInterface $webform_submission, array $options = []) {

  /** @var \Drupal\webform_attachment\Element\WebformAttachmentInterface $attachment_element */
  $attachment_element = $this
    ->getFormElementClassDefinition();
  $format = $this
    ->getItemFormat($element);
  switch ($format) {
    case 'name':
      return $attachment_element::getFileName($element, $webform_submission);
    default:
    case 'link':
    case 'url':
      $fileUrl = $attachment_element::getFileUrl($element, $webform_submission);
      return $fileUrl ? $fileUrl
        ->toString() : '';
  }
}