private function devel_token_object($entity_type, $entity_id, Request $request)
 {
     $this->moduleHandler->loadInclude('token', 'pages.inc');
     $entity = entity_load($entity_type, $entity_id);
     $header = array(t('Token'), t('Value'));
     $rows = array();
     $options = array('flat' => TRUE, 'values' => TRUE, 'data' => array($entity_type => $entity));
     $tree = token_build_tree($entity_type, $options);
     foreach ($tree as $token => $token_info) {
         if (!empty($token_info['restricted'])) {
             continue;
         }
         if (!isset($token_info['value']) && !empty($token_info['parent']) && !isset($tree[$token_info['parent']]['value'])) {
             continue;
         }
         $row = _token_token_tree_format_row($token, $token_info);
         unset($row['data']['description']);
         unset($row['data']['name']);
         $rows[] = $row;
     }
     $build['tokens'] = array('#theme' => 'tree_table', '#header' => $header, '#rows' => $rows, '#attributes' => array('class' => array('token-tree')), '#empty' => t('No tokens available.'), '#attached' => array('library' => array('token/token')));
     return $build;
 }
 /**
  * Retrieves suggestions for block category autocompletion.
  *
  * @param \Symfony\Component\HttpFoundation\Request $request
  *   The current request.
  * @param string $token_type
  *   The token type.
  * @param string $filter
  *   The autocomplete filter.
  *
  * @return \Symfony\Component\HttpFoundation\JsonResponse
  *   A JSON response containing autocomplete suggestions.
  */
 public function autocomplete($token_type, $filter, Request $request)
 {
     $filter = substr($filter, strrpos($filter, '['));
     $matches = array();
     if (!Unicode::strlen($filter)) {
         $matches["[{$token_type}:"] = 0;
     } else {
         $depth = max(1, substr_count($filter, ':'));
         $tree = token_build_tree($token_type, array('flat' => TRUE, 'depth' => $depth));
         foreach (array_keys($tree) as $token) {
             if (strpos($token, $filter) === 0) {
                 $matches[$token] = levenshtein($token, $filter);
                 if (isset($tree[$token]['children'])) {
                     $token = rtrim($token, ':]') . ':';
                     $matches[$token] = levenshtein($token, $filter);
                 }
             }
         }
     }
     asort($matches);
     $keys = array_keys($matches);
     $matches = array_combine($keys, $keys);
     return new JsonResponse($matches);
 }