You are here

protected static function TokenTreeTable::formatRow in Token 8

1 call to TokenTreeTable::formatRow()
TokenTreeTable::preRenderTokenTree in src/Element/TokenTreeTable.php
Pre-render the token tree to transform rows in the token tree.

File

src/Element/TokenTreeTable.php, line 115

Class

TokenTreeTable
Provides a render element for a token tree table.

Namespace

Drupal\token\Element

Code

protected static function formatRow($token, $token_info, $columns, $is_group = FALSE) {
  $row = [
    'id' => static::cleanCssIdentifier($token),
    'data-tt-id' => static::cleanCssIdentifier($token),
    'class' => [],
    'data' => [],
  ];
  foreach ($columns as $col) {
    switch ($col) {
      case 'name':
        $row['data'][$col] = $token_info['name'];
        break;
      case 'token':
        $row['data'][$col]['data'] = $token;
        $row['data'][$col]['class'][] = 'token-key';
        break;
      case 'description':
        $row['data'][$col] = isset($token_info['description']) ? $token_info['description'] : '';
        break;
      case 'value':
        $row['data'][$col] = !$is_group && isset($token_info['value']) ? $token_info['value'] : '';
        break;
    }
  }
  if ($is_group) {

    // This is a token type/group.
    $row['class'][] = 'token-group';
  }
  elseif (!empty($token_info['parent'])) {
    $row['data-tt-parent-id'] = static::cleanCssIdentifier($token_info['parent']);
    unset($row['parent']);
  }
  return $row;
}