You are here

public static function FormTrait::createTokenBrowser in Markdown 8.2

Creates a Token browser element for use when dealing with tokens.

Parameters

array $tokenTypes: An array of token types.

bool $globalTypes: Flag indicating whether to display global tokens.

bool $dialog: Flag indicating whether to show the browser in a dialog.

Return value

array A new render array element.

1 call to FormTrait::createTokenBrowser()
ExternalLinkExtension::buildConfigurationForm in src/Plugin/Markdown/CommonMark/Extension/ExternalLinkExtension.php
Form constructor.

File

src/Traits/FormTrait.php, line 219

Class

FormTrait
Trait providing helpful methods when dealing with forms.

Namespace

Drupal\markdown\Traits

Code

public static function createTokenBrowser(array $tokenTypes = [], $globalTypes = TRUE, $dialog = TRUE) {
  if (!isset(static::$tokenModuleExists)) {
    static::$tokenModuleExists = \Drupal::moduleHandler()
      ->moduleExists('token');
  }
  if (static::$tokenModuleExists) {
    return [
      '#type' => 'item',
      '#input' => FALSE,
      '#theme' => 'token_tree_link',
      '#token_types' => $tokenTypes,
      '#global_types' => $globalTypes,
      '#dialog' => $dialog,
    ];
  }
  return [
    '#type' => 'item',
    '#input' => FALSE,
    '#markup' => t('To browse available tokens, install the @token module.', [
      '@token' => Link::fromTextAndUrl('Token', Url::fromUri('https://www.drupal.org/project/token', [
        'attributes' => [
          'target' => '_blank',
        ],
      ]))
        ->toString(),
    ]),
  ];
}