class Url

Same name in this branch
  1. 9 core/lib/Drupal/Core/Render/Element/Url.php \Drupal\Core\Render\Element\Url
  2. 9 core/lib/Drupal/Core/Url.php \Drupal\Core\Url
Same name and namespace in other branches
  1. 11.x core/modules/views/src/Plugin/views/field/Url.php \Drupal\views\Plugin\views\field\Url
  2. 11.x core/lib/Drupal/Core/Render/Element/Url.php \Drupal\Core\Render\Element\Url
  3. 11.x core/lib/Drupal/Core/Url.php \Drupal\Core\Url
  4. 10 core/modules/views/src/Plugin/views/field/Url.php \Drupal\views\Plugin\views\field\Url
  5. 10 core/lib/Drupal/Core/Render/Element/Url.php \Drupal\Core\Render\Element\Url
  6. 10 core/lib/Drupal/Core/Url.php \Drupal\Core\Url
  7. 8.9.x core/modules/views/src/Plugin/views/field/Url.php \Drupal\views\Plugin\views\field\Url
  8. 8.9.x core/lib/Drupal/Core/Render/Element/Url.php \Drupal\Core\Render\Element\Url
  9. 8.9.x core/lib/Drupal/Core/Url.php \Drupal\Core\Url

Field handler to provide simple renderer that turns a URL into a clickable link.

Plugin annotation

@ViewsField("url");

Hierarchy

Expanded class hierarchy of Url

Related topics

150 string references to 'Url'
AggregatorFeedViewsFieldAccessTest::testAggregatorFeedFields in core/modules/aggregator/tests/src/Kernel/Views/AggregatorFeedViewsFieldAccessTest.php
Checks access for aggregator_feed fields.
AliasPathProcessorTest::providerTestProcessOutbound in core/modules/path_alias/tests/src/Unit/PathProcessor/AliasPathProcessorTest.php
AliasPathProcessorTest::testProcessInbound in core/modules/path_alias/tests/src/Unit/PathProcessor/AliasPathProcessorTest.php
Tests the processInbound method.
AliasPathProcessorTest::testProcessOutbound in core/modules/path_alias/tests/src/Unit/PathProcessor/AliasPathProcessorTest.php
@covers ::processOutbound[[api-linebreak]]
ArgumentPluginBase::getCacheContexts in core/modules/views/src/Plugin/views/argument/ArgumentPluginBase.php

... See full list

File

core/modules/views/src/Plugin/views/field/Url.php, line 17

Namespace

Drupal\views\Plugin\views\field
View source
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');
    }
  }

}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.