protected function WebformManagedFileBase::formatHtmlItem in Webform 6.x
Same name and namespace in other branches
- 8.5 src/Plugin/WebformElement/WebformManagedFileBase.php \Drupal\webform\Plugin\WebformElement\WebformManagedFileBase::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
2 calls to WebformManagedFileBase::formatHtmlItem()
- WebformImageFile::formatHtmlItem in src/
Plugin/ WebformElement/ WebformImageFile.php - Format an element's value as HTML.
- WebformManagedFileBase::previewManagedFile in src/
Plugin/ WebformElement/ WebformManagedFileBase.php - Preview a managed file element upload.
1 method overrides WebformManagedFileBase::formatHtmlItem()
- WebformImageFile::formatHtmlItem in src/
Plugin/ WebformElement/ WebformImageFile.php - Format an element's value as HTML.
File
- src/
Plugin/ WebformElement/ WebformManagedFileBase.php, line 319
Class
- WebformManagedFileBase
- Provides a base class webform 'managed_file' elements.
Namespace
Drupal\webform\Plugin\WebformElementCode
protected function formatHtmlItem(array $element, WebformSubmissionInterface $webform_submission, array $options = []) {
$value = $this
->getValue($element, $webform_submission, $options);
$file = $this
->getFile($element, $value, $options);
if (empty($file)) {
return '';
}
$format = $this
->getItemFormat($element);
switch ($format) {
case 'basename':
case 'extension':
case 'data':
case 'id':
case 'mime':
case 'name':
case 'raw':
case 'size':
case 'url':
case 'value':
return $this
->formatTextItem($element, $webform_submission, $options);
case 'link':
return [
'#theme' => 'file_link',
'#file' => $file,
];
default:
$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,
];
}
}