You are here

protected function WebformAttachmentBase::formatHtmlItem 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::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

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

Class

WebformAttachmentBase
Provides a base class for 'webform_attachment' elements.

Namespace

Drupal\webform_attachment\Plugin\WebformElement

Code

protected function formatHtmlItem(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);
    case 'url':
      return $attachment_element::getFileUrl($element, $webform_submission)
        ->toString();
    default:
    case 'link':
      return $attachment_element::getFileLink($element, $webform_submission);
  }
}