protected function WebformEntityReferenceTrait::formatHtmlItem in Webform 6.x
Same name and namespace in other branches
- 8.5 src/Plugin/WebformElement/WebformEntityReferenceTrait.php \Drupal\webform\Plugin\WebformElement\WebformEntityReferenceTrait::formatHtmlItem()
File
- src/
Plugin/ WebformElement/ WebformEntityReferenceTrait.php, line 79
Class
- WebformEntityReferenceTrait
- Provides an 'entity_reference' trait.
Namespace
Drupal\webform\Plugin\WebformElementCode
protected function formatHtmlItem(array $element, WebformSubmissionInterface $webform_submission, array $options = []) {
$entity = $this
->getTargetEntity($element, $webform_submission, $options);
if (empty($entity)) {
return '';
}
$format = $this
->getItemFormat($element);
switch ($format) {
case 'raw':
case 'value':
case 'id':
case 'label':
case 'text':
case 'breadcrumb':
return $this
->formatTextItem($element, $webform_submission, $options);
case 'link':
if ($entity
->hasLinkTemplate('canonical')) {
return [
'#type' => 'link',
'#title' => $entity
->label(),
'#url' => $entity
->toUrl()
->setAbsolute(TRUE),
];
}
else {
switch ($entity
->getEntityTypeId()) {
case 'file':
/** @var \Drupal\file\FileInterface $entity */
if ($entity
->access('download')) {
return [
'#type' => 'link',
'#title' => $entity
->label(),
'#url' => UrlGenerator::fromUri(file_create_url($entity
->getFileUri())),
];
}
else {
return $this
->formatTextItem($element, $webform_submission, $options);
}
default:
return $this
->formatTextItem($element, $webform_submission, $options);
}
}
default:
return $this->entityTypeManager
->getViewBuilder($entity
->getEntityTypeId())
->view($entity, $format);
}
}