You are here

public function FormAssemblyEntityForm::buildTokenElement in FormAssembly 8

Helper method to build the token link render array.

Parameters

int $weight: The element weight.

string $description: An optional description.

Return value

array The render array.

1 call to FormAssemblyEntityForm::buildTokenElement()
FormAssemblyEntityForm::buildForm in src/Form/FormAssemblyEntityForm.php
Form constructor.

File

src/Form/FormAssemblyEntityForm.php, line 127

Class

FormAssemblyEntityForm
Form controller for FormAssembly Form edit forms.

Namespace

Drupal\formassembly\Form

Code

public function buildTokenElement($weight = 90, $description = NULL) {
  if (!$this->moduleHandler
    ->moduleExists('token')) {
    return [];
  }

  // Not injecting the service as it may not exist.
  $token_tree = \Drupal::service('token.tree_builder')
    ->buildAllRenderable([
    'click_insert' => FALSE,
    'show_restricted' => TRUE,
    'show_nested' => FALSE,
  ]);
  $build = [
    '#type' => 'details',
    '#title' => $this
      ->t('All available tokens'),
    '#weight' => $weight,
    'token_tree_link' => $token_tree,
  ];
  if ($description) {
    $build['description'] = [
      '#prefix' => ' ',
      '#markup' => $description,
    ];
  }
  return $build;
}