
| Current Path : /var/www/html1/ift-informatik.de_drupal9/web/core/modules/views/src/Plugin/views/field/ |
Linux ift1.ift-informatik.de 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64 |
| Current File : //var/www/html1/ift-informatik.de_drupal9/web/core/modules/views/src/Plugin/views/field/Url.php |
<?php
namespace Drupal\views\Plugin\views\field;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Link;
use Drupal\Core\Url as CoreUrl;
use Drupal\views\ResultRow;
/**
* Field handler to provide simple renderer that turns a URL into a clickable link.
*
* @ingroup views_field_handlers
*
* @ViewsField("url")
*/
class Url extends FieldPluginBase {
/**
* {@inheritdoc}
*/
protected function defineOptions() {
$options = parent::defineOptions();
$options['display_as_link'] = ['default' => TRUE];
return $options;
}
/**
* Provide link to the page being visited.
*/
public function buildOptionsForm(&$form, FormStateInterface $form_state) {
$form['display_as_link'] = [
'#title' => $this->t('Display as link'),
'#type' => 'checkbox',
'#default_value' => !empty($this->options['display_as_link']),
];
parent::buildOptionsForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function render(ResultRow $values) {
$value = $this->getValue($values);
if (!empty($this->options['display_as_link'])) {
// @todo Views should expect and store a leading /. See:
// https://www.drupal.org/node/2423913
return Link::fromTextAndUrl($this->sanitizeValue($value), CoreUrl::fromUserInput('/' . $value))->toString();
}
else {
return $this->sanitizeValue($value, 'url');
}
}
}