WebformEntityReferenceUrlFormatter.php in Webform 8.5
File
src/Plugin/Field/FieldFormatter/WebformEntityReferenceUrlFormatter.php
View source
<?php
namespace Drupal\webform\Plugin\Field\FieldFormatter;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\webform\Plugin\WebformSourceEntity\QueryStringWebformSourceEntity;
class WebformEntityReferenceUrlFormatter extends WebformEntityReferenceFormatterBase {
public function viewElements(FieldItemListInterface $items, $langcode) {
$source_entity = $items
->getEntity();
$elements = [];
$entities = $this
->getEntitiesToView($items, $langcode);
foreach ($entities as $delta => $entity) {
$link_options = QueryStringWebformSourceEntity::getRouteOptionsQuery($source_entity);
$link = [
'#plain_text' => $entity
->toUrl('canonical', $link_options)
->toString(),
];
$elements[$delta] = $link;
$this
->setCacheContext($elements[$delta], $entity, $items[$delta]);
}
return $elements;
}
}