WebformLink.php in Webform 8.5
File
src/Plugin/WebformElement/WebformLink.php
View source
<?php
namespace Drupal\webform\Plugin\WebformElement;
use Drupal\Component\Render\FormattableMarkup;
use Drupal\webform\WebformSubmissionInterface;
class WebformLink extends WebformCompositeBase {
protected function defineDefaultProperties() {
$properties = parent::defineDefaultProperties();
unset($properties['select2'], $properties['chosed']);
return $properties;
}
protected function formatHtmlItemValue(array $element, WebformSubmissionInterface $webform_submission, array $options = []) {
$value = $this
->getValue($element, $webform_submission, $options);
return [
'link' => [
'#type' => 'link',
'#title' => $value['title'],
'#url' => \Drupal::pathValidator()
->getUrlIfValid($value['url']),
],
];
}
protected function formatTextItemValue(array $element, WebformSubmissionInterface $webform_submission, array $options = []) {
$value = $this
->getValue($element, $webform_submission, $options);
return [
'link' => new FormattableMarkup('@title (@url)', [
'@title' => $value['title'],
'@url' => $value['url'],
]),
];
}
}