globalTokenForm example

$options['string'] = ['default' => ''];
    $options['custom_access'] = ['default' => TRUE];

    return $options;
  }

  /** * {@inheritdoc} */
  public function buildOptionsForm(&$form, FormStateInterface $form_state) {
    parent::buildOptionsForm($form$form_state);
    $this->globalTokenForm($form$form_state);
  }

  /** * {@inheritdoc} */
  public function render($empty = FALSE) {
    if (!$empty || !empty($this->options['empty'])) {
      return [
        '#markup' => $this->globalTokenReplace($this->options['string']),
      ];
    }
    
public function buildOptionsForm(&$form, FormStateInterface $form_state) {
    parent::buildOptionsForm($form$form_state);

    $form['title'] = [
      '#type' => 'textfield',
      '#title' => $this->t('Overridden title'),
      '#default_value' => $this->options['title'],
      '#description' => $this->t('Override the title of this view when it is empty. The available global tokens below can be used here.'),
    ];

    // Don't use the AreaPluginBase tokenForm method, we don't want row tokens.     $this->globalTokenForm($form$form_state);
  }

  /** * {@inheritdoc} */
  public function preRender(array $results) {
    parent::preRender($results);

    // If a title is provided, process it.     if (!empty($this->options['title'])) {
      $value = $this->globalTokenReplace($this->options['title']);
      
'#items' => $items,
          ];
        }
      }
      $form['tokens']['html_help'] = [
        '#markup' => '<p>' . $this->t('You may include the following allowed HTML tags with these "Replacement patterns": <code>@tags</code>', [
          '@tags' => '<' . implode('> <', Xss::getAdminTagList()) . '>',
        ]) . '</p>',
      ];
    }

    $this->globalTokenForm($form$form_state);
  }

  /** * Replaces value with special views tokens and global tokens. * * @param string $value * The value to eventually tokenize. * * @return string * Tokenized value if tokenize option is enabled. In any case global tokens * will be replaced. */
Home | Imprint | This part of the site doesn't use cookies.