You are here

public function MenuTokenSupportedTokensController::content in Menu Token 8

Same name and namespace in other branches
  1. 9.1.x src/Controller/MenuTokenSupportedTokensController.php \Drupal\menu_token\Controller\MenuTokenSupportedTokensController::content()

Controller method for displaying supported token page.

Return value

array Return the build array.

1 string reference to 'MenuTokenSupportedTokensController::content'
menu_token.routing.yml in ./menu_token.routing.yml
menu_token.routing.yml

File

src/Controller/MenuTokenSupportedTokensController.php, line 45

Class

MenuTokenSupportedTokensController
Class MenuTokenSupportedTokensController.

Namespace

Drupal\menu_token\Controller

Code

public function content() {

  /*
   * Load the configuration from configuration entity
   * and check for available entities.
   */
  $availableEntitiesConfiguration = $this->configFactory
    ->get('menu_token.availableentitiesconfiguration');
  $data = $availableEntitiesConfiguration
    ->getRawData();
  $renderable = [];
  foreach ($data['available_entities'] as $config_key => $config_item) {
    if ($config_item !== 0) {
      $renderable[] = $config_key;
    }
  }

  // Build the token tree for display.
  $token_tree = $this->treeBuilder
    ->buildRenderable($renderable, [
    'click_insert' => FALSE,
    'show_restricted' => FALSE,
    'show_nested' => FALSE,
  ]);

  // Create the html output.
  $output = '<dt>' . t('The list of the currently available tokens supported by menu_token are shown below.') . '</dt>';
  $output .= '<br /><dd>' . $this->renderer
    ->render($token_tree) . '</dd>';
  $output .= '</dl>';
  $build = [
    '#type' => 'markup',
    '#markup' => $output,
  ];
  return $build;
}