You are here

protected function BaseUrl::getReplacementTokens in Views base url 2.0.x

Same name and namespace in other branches
  1. 8 src/Plugin/views/field/BaseUrl.php \Drupal\views_base_url\Plugin\views\field\BaseUrl::getReplacementTokens()

Returns a list of the available fields and arguments for token replacement.

Return value

array Array of default help text and list of tokens.

1 call to BaseUrl::getReplacementTokens()
BaseUrl::buildOptionsForm in src/Plugin/views/field/BaseUrl.php
Default options form that provides the label widget that all fields should have.

File

src/Plugin/views/field/BaseUrl.php, line 240

Class

BaseUrl
A handler to output site's base url.

Namespace

Drupal\views_base_url\Plugin\views\field

Code

protected function getReplacementTokens() {

  // Setup the tokens for fields.
  $previous = $this
    ->getPreviousFieldLabels();
  $optgroup_arguments = (string) $this
    ->t('Arguments');
  $optgroup_fields = (string) $this
    ->t('Fields');
  foreach ($previous as $id => $label) {
    $options[$optgroup_fields]["{{ {$id} }}"] = substr(strrchr($label, ":"), 2);
  }

  // Add the field to the list of options.
  $options[$optgroup_fields]["{{ {$this->options['id']} }}"] = substr(strrchr($this
    ->adminLabel(), ":"), 2);
  foreach ($this->view->display_handler
    ->getHandlers('argument') as $arg => $handler) {
    $options[$optgroup_arguments]["{{ arguments.{$arg} }}"] = $this
      ->t('@argument title', [
      '@argument' => $handler
        ->adminLabel(),
    ]);
    $options[$optgroup_arguments]["{{ raw_arguments.{$arg} }}"] = $this
      ->t('@argument input', [
      '@argument' => $handler
        ->adminLabel(),
    ]);
  }
  $this
    ->documentSelfTokens($options[$optgroup_fields]);

  // Default text.
  $output[] = [
    [
      '#markup' => '<p>' . $this
        ->t('You must add some additional fields to this display before using this field. These fields may be marked as <em>Exclude from display</em> if you prefer. Note that due to rendering order, you cannot use fields that come after this field; if you need a field not listed here, rearrange your fields.') . '</p>',
    ],
    [
      '#markup' => '<p>' . $this
        ->t("The following replacement tokens are available for this field. Note that due to rendering order, you cannot use fields that come after this field; if you need a field not listed here, rearrange your fields.") . '</p>',
    ],
  ];
  foreach (array_keys($options) as $type) {
    if (!empty($options[$type])) {
      $items = [];
      foreach ($options[$type] as $key => $value) {
        $items[] = $key . ' == ' . $value;
      }
      $item_list = [
        '#theme' => 'item_list',
        '#items' => $items,
      ];
      $output[] = $item_list;
    }
  }
  return $output;
}