You are here

protected function WebformImageFile::formatHtmlItem in Webform 8.5

Same name and namespace in other branches
  1. 6.x src/Plugin/WebformElement/WebformImageFile.php \Drupal\webform\Plugin\WebformElement\WebformImageFile::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 WebformManagedFileBase::formatHtmlItem

File

src/Plugin/WebformElement/WebformImageFile.php, line 92

Class

WebformImageFile
Provides a 'webform_image_file' element.

Namespace

Drupal\webform\Plugin\WebformElement

Code

protected function formatHtmlItem(array $element, WebformSubmissionInterface $webform_submission, array $options = []) {
  $value = $this
    ->getValue($element, $webform_submission, $options);
  $file = $this
    ->getFile($element, $value, $options);
  $format = $this
    ->getItemFormat($element);
  if (strpos($format, ':') === FALSE) {
    return parent::formatHtmlItem($element, $webform_submission, $options);
  }
  else {
    list($style_name, $format) = explode(':', $format);
    $theme = str_replace('webform_', 'webform_element_', $this
      ->getPluginId());
    if (strpos($theme, 'webform_') !== 0) {
      $theme = 'webform_element_' . $theme;
    }
    return [
      '#theme' => $theme,
      '#element' => $element,
      '#value' => $value,
      '#options' => $options,
      '#file' => $file,
      '#style_name' => $style_name,
      '#format' => $format,
    ];
  }
}