class Path

Field handler to present the path to the node.

Plugin annotation

@ViewsField("node_path");

Hierarchy

  • class \Drupal\node\Plugin\views\field\Path

Expanded class hierarchy of Path

Deprecated

in drupal:8.5.0 and is removed from drupal:9.0.0. Use @ViewsField("entity_link") with 'output_url_as_text' set.

11 string references to 'Path'
AliasRepository::preloadPathAlias in core/lib/Drupal/Core/Path/AliasRepository.php
Pre-loads path alias information for a given list of system paths.
AliasStorage::aliasExists in core/lib/Drupal/Core/Path/AliasStorage.php
Checks if alias already exists.
AliasStorage::delete in core/lib/Drupal/Core/Path/AliasStorage.php
Deletes a URL alias.
AliasStorage::getAliasesForAdminListing in core/lib/Drupal/Core/Path/AliasStorage.php
Loads aliases for admin listing.
AliasStorage::load in core/lib/Drupal/Core/Path/AliasStorage.php
Fetches a specific URL alias from the database.

... See full list

File

core/modules/node/src/Plugin/views/field/Path.php, line 24

Namespace

Drupal\node\Plugin\views\field
View source
class Path extends FieldPluginBase {
  
  /**
   * {@inheritdoc}
   */
  public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL) {
    parent::init($view, $display, $options);
    $this->additional_fields['nid'] = 'nid';
  }
  
  /**
   * {@inheritdoc}
   */
  protected function defineOptions() {
    $options = parent::defineOptions();
    $options['absolute'] = [
      'default' => FALSE,
    ];
    return $options;
  }
  
  /**
   * {@inheritdoc}
   */
  public function buildOptionsForm(&$form, FormStateInterface $form_state) {
    parent::buildOptionsForm($form, $form_state);
    $form['absolute'] = [
      '#type' => 'checkbox',
      '#title' => $this->t('Use absolute link (begins with "http://")'),
      '#default_value' => $this->options['absolute'],
      '#description' => $this->t('Enable this option to output an absolute link. Required if you want to use the path as a link destination (as in "output this field as a link" above).'),
      '#fieldset' => 'alter',
    ];
  }
  
  /**
   * {@inheritdoc}
   */
  public function query() {
    $this->ensureMyTable();
    $this->addAdditionalFields();
  }
  
  /**
   * {@inheritdoc}
   */
  public function render(ResultRow $values) {
    $nid = $this->getValue($values, 'nid');
    return [
      '#markup' => Url::fromRoute('entity.node.canonical', [
        'node' => $nid,
      ], [
        'absolute' => $this->options['absolute'],
      ])
        ->toString(),
    ];
  }

}

Members

Title Sort descending Modifiers Object type Summary
Path::buildOptionsForm public function Default options form that provides the label widget that all fields
should have.
Path::defineOptions protected function Information about options for all kinds of purposes will be held here.
Path::init public function Initialize the plugin.
Path::query public function Called to add the field to a query.
Path::render public function Renders the field.

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