You are here

Link.php in Simplenews 8.2

Same filename and directory in other branches
  1. 8 src/Plugin/views/field/Link.php
  2. 3.x src/Plugin/views/field/Link.php

File

src/Plugin/views/field/Link.php
View source
<?php

namespace Drupal\simplenews\Plugin\views\field;

use Drupal\Core\Form\FormStateInterface;
use Drupal\views\Plugin\views\field\FieldPluginBase;
use Drupal\views\ResultRow;

/**
 * Field handler to present a link to the subscriber.
 *
 * @ingroup views_field_handlers
 *
 * @ViewsField("subscriber_link")
 */
class Link extends FieldPluginBase {

  /**
   * {@inheritdoc}
   */
  public function usesGroupBy() {
    return FALSE;
  }

  /**
   * {@inheritdoc}
   */
  protected function defineOptions() {
    $options = parent::defineOptions();
    $options['text'] = [
      'default' => '',
    ];
    return $options;
  }

  /**
   * {@inheritdoc}
   */
  public function buildOptionsForm(&$form, FormStateInterface $form_state) {
    $form['text'] = [
      '#type' => 'textfield',
      '#title' => $this
        ->t('Text to display'),
      '#default_value' => $this->options['text'],
    ];
    parent::buildOptionsForm($form, $form_state);

    // The path is set by renderLink function so don't allow to set it.
    $form['alter']['path'] = [
      '#access' => FALSE,
    ];
    $form['alter']['external'] = [
      '#access' => FALSE,
    ];
  }

  /**
   * {@inheritdoc}
   */
  public function query() {
    $this
      ->addAdditionalFields();
  }

  /**
   * {@inheritdoc}
   */
  public function render(ResultRow $values) {
    if ($entity = $this
      ->getEntity($values)) {
      return $this
        ->renderLink($entity, $values);
    }
  }

}

Classes

Namesort descending Description
Link Field handler to present a link to the subscriber.