class TokenTreeTable in Token 8
Provides a render element for a token tree table.
Plugin annotation
@RenderElement("token_tree_table");
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\Core\Render\Element\RenderElement implements ElementInterface
- class \Drupal\Core\Render\Element\FormElement implements FormElementInterface
- class \Drupal\Core\Render\Element\Table
- class \Drupal\token\Element\TokenTreeTable
- class \Drupal\Core\Render\Element\Table
- class \Drupal\Core\Render\Element\FormElement implements FormElementInterface
- class \Drupal\Core\Render\Element\RenderElement implements ElementInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of TokenTreeTable
2 #type uses of TokenTreeTable
- TokenDevelController::renderTokenTree in src/
Controller/ TokenDevelController.php - Render the token tree for the specified entity.
- TreeBuilder::buildRenderable in src/
TreeBuilder.php - Build a render array with token tree built as per specified options.
File
- src/
Element/ TokenTreeTable.php, line 13
Namespace
Drupal\token\ElementView source
class TokenTreeTable extends Table {
protected static $cssFilter = [
' ' => '-',
'_' => '-',
'/' => '-',
'[' => '-',
']' => '',
':' => '--',
'?' => '',
'<' => '-',
'>' => '-',
];
/**
* {@inheritdoc}
*/
public function getInfo() {
$class = get_class($this);
return [
'#header' => [],
'#rows' => [],
'#token_tree' => [],
'#columns' => [
'name',
'token',
'description',
],
'#empty' => '',
'#show_restricted' => FALSE,
'#show_nested' => FALSE,
'#skip_empty_values' => FALSE,
'#click_insert' => TRUE,
'#sticky' => FALSE,
'#responsive' => TRUE,
'#input' => FALSE,
'#pre_render' => [
[
$class,
'preRenderTokenTree',
],
[
$class,
'preRenderTable',
],
],
'#theme' => 'table__token_tree',
'#attached' => [
'library' => [
'token/token',
],
],
];
}
/**
* Pre-render the token tree to transform rows in the token tree.
*
* @param array $element
*
* @return array
* The processed element.
*/
public static function preRenderTokenTree($element) {
$multiple_token_types = count($element['#token_tree']) > 1;
foreach ($element['#token_tree'] as $token_type => $type_info) {
// Do not show nested tokens.
if (!empty($type_info['nested']) && empty($element['#show_nested'])) {
continue;
}
if ($multiple_token_types) {
$row = static::formatRow($token_type, $type_info, $element['#columns'], TRUE);
$element['#rows'][] = $row;
}
foreach ($type_info['tokens'] as $token => $token_info) {
if (!empty($token_info['restricted']) && empty($element['#show_restricted'])) {
continue;
}
if ($element['#skip_empty_values'] && empty($token_info['value']) && !empty($token_info['parent']) && !isset($tree[$token_info['parent']]['value'])) {
continue;
}
if ($multiple_token_types && !isset($token_info['parent'])) {
$token_info['parent'] = $token_type;
}
$row = static::formatRow($token, $token_info, $element['#columns']);
$element['#rows'][] = $row;
}
}
if (!empty($element['#rows'])) {
$element['#attached']['library'][] = 'token/jquery.treeTable';
}
// Fill headers if one is not specified.
if (empty($element['#header'])) {
$column_map = [
'name' => t('Name'),
'token' => t('Token'),
'value' => t('Value'),
'description' => t('Description'),
];
foreach ($element['#columns'] as $col) {
$element['#header'][] = $column_map[$col];
}
}
$element['#attributes']['class'][] = 'token-tree';
if ($element['#click_insert']) {
$element['#caption'] = t('Click a token to insert it into the field you\'ve last clicked.');
$element['#attributes']['class'][] = 'token-click-insert';
}
return $element;
}
protected static function cleanCssIdentifier($id) {
return 'token-' . Html::cleanCssIdentifier(trim($id, '[]'), static::$cssFilter);
}
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;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
FormElement:: |
public static | function | Adds autocomplete functionality to elements. | |
FormElement:: |
public static | function | #process callback for #pattern form element property. | |
FormElement:: |
public static | function | #element_validate callback for #pattern form element property. | |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
PluginBase:: |
public | function | Constructs a \Drupal\Component\Plugin\PluginBase object. | 92 |
RenderElement:: |
public static | function | Adds Ajax information about an element to communicate with JavaScript. | |
RenderElement:: |
public static | function | Adds members of this group as actual elements for rendering. | |
RenderElement:: |
public static | function | Form element processing handler for the #ajax form property. | 1 |
RenderElement:: |
public static | function | Arranges elements into groups. | |
RenderElement:: |
public static | function |
Sets a form element's class attribute. Overrides ElementInterface:: |
|
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
Table:: |
public static | function | #pre_render callback to transform children of an element of #type 'table'. | |
Table:: |
public static | function | #process callback for #type 'table' to add tableselect support. | |
Table:: |
public static | function | #element_validate callback for #type 'table'. | |
Table:: |
public static | function |
Determines how user input is mapped to an element's #value property. Overrides FormElement:: |
1 |
TokenTreeTable:: |
protected static | property | ||
TokenTreeTable:: |
protected static | function | ||
TokenTreeTable:: |
protected static | function | ||
TokenTreeTable:: |
public | function |
Returns the element properties for this element. Overrides Table:: |
|
TokenTreeTable:: |
public static | function | Pre-render the token tree to transform rows in the token tree. |