How can I use a replacement pattern in a custom field? I just created a new custom field in a view, but I would like to use replacement patterns in that field. Is it possible to do this?

class CustomButtonField extends FieldPluginBase {

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

  /**
   * {@inheritdoc}
   */
  public function query() {
    // Do nothing -- to override the parent query.
  }

  /**
   * {@inheritdoc}
   */
  protected function defineOptions() {
    $options = parent::defineOptions();

    $options['target'] = ['default' =&gt; FALSE];
    $options['class'] = ['default' =&gt; FALSE];
    $options['text'] = ['default' =&gt; FALSE];
    return $options;
  }

  /**
   * {@inheritdoc}
   */
  public function buildOptionsForm(&amp;amp;$form, FormStateInterface $form_state) {
    $form['target'] = array(
      '#title' =&gt; $this-&gt;t('The target id of the button'),
      '#type' =&gt; 'textfield',
      '#default_value' =&gt; $this-&gt;options['target'],
    );

    $form['class'] = array(
      '#title' =&gt; $this-&gt;t('The class of the button'),
      '#type' =&gt; 'textfield',
      '#default_value' =&gt; $this-&gt;options['class'],
    );

    $form['text'] = array(
      '#title' =&gt; $this-&gt;t('The text of the button'),
      '#type' =&gt; 'textfield',
      '#default_value' =&gt; $this-&gt;options['text'],
    );

    parent::buildOptionsForm($form, $form_state);
  }

  /**
   * {@inheritdoc}
   */
  public function render(ResultRow $values) {
    return [
      '#theme'  =&gt; 'custom_button',
      '#target' =&gt; $this-&gt;options['target'],
      '#class'  =&gt; $this-&gt;options['class'],
      '#text'   =&gt; $this-&gt;options['text']
    ];
  }
}


How can I use replacement patterns in $form['text']?
Take a look to \Drupal\views\Plugin\views\field\FieldPluginBase::renderText

/**
* {@inheritdoc}
*/
public function render(ResultRow $values) {
  $tokens = $this-&gt;getRenderTokens($this-&gt;options['text']);
  return [
    '#theme'  =&gt; 'custom_button',
    '#target' =&gt; $this-&gt;options['target'],
    '#class'  =&gt; $this-&gt;options['class'],
    '#text'   =&gt; $this-&gt;viewsTokenReplace($this-&gt;options['text'], $tokens),
  ];
}