You are here

protected function TokenDevelController::renderTokenTree in Token 8

Render the token tree for the specified entity.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity for which the token tree should be rendered.

Return value

array Render array of the token tree for the $entity.

See also

static::entityLoad

1 call to TokenDevelController::renderTokenTree()
TokenDevelController::entityTokens in src/Controller/TokenDevelController.php
Prints the loaded structure of the current entity.

File

src/Controller/TokenDevelController.php, line 75

Class

TokenDevelController
Devel integration for tokens.

Namespace

Drupal\token\Controller

Code

protected function renderTokenTree(EntityInterface $entity) {
  $this
    ->moduleHandler()
    ->loadInclude('token', 'pages.inc');
  $entity_type = $entity
    ->getEntityTypeId();
  $token_type = $this->entityMapper
    ->getTokenTypeForEntityType($entity_type);
  $options = [
    'flat' => TRUE,
    'values' => TRUE,
    'data' => [
      $token_type => $entity,
    ],
  ];
  $token_tree = [
    $token_type => [
      'tokens' => $this->treeBuilder
        ->buildTree($token_type, $options),
    ],
  ];

  //    foreach ($tree as $token => $token_info) {
  //      if (!isset($token_info['value']) && !empty($token_info['parent']) && !isset($tree[$token_info['parent']]['value'])) {
  //        continue;
  //      }
  //    }
  $build['tokens'] = [
    '#type' => 'token_tree_table',
    '#show_restricted' => FALSE,
    '#show_nested' => FALSE,
    '#skip_empty_values' => TRUE,
    '#token_tree' => $token_tree,
    '#columns' => [
      'token',
      'value',
    ],
    '#empty' => $this
      ->t('No tokens available.'),
  ];
  return $build;
}