public function TokenFilter::tips in Token Filter 8
Generates a filter's tip.
A filter's tips should be informative and to the point. Short tips are preferably one-liners.
@todo Split into getSummaryItem() and buildGuidelines().
Parameters
bool $long: Whether this callback should return a short tip to display in a form (FALSE), or whether a more elaborate filter tips should be returned for template_preprocess_filter_tips() (TRUE).
Return value
string|null Translated text to display as a tip, or NULL if this filter has no tip.
Overrides FilterBase::tips
File
- src/
Plugin/ Filter/ TokenFilter.php, line 138
Class
- TokenFilter
- Provides a filter that replaces global and entity tokens with their values.
Namespace
Drupal\token_filter\Plugin\FilterCode
public function tips($long = FALSE) {
$build = [];
$build[] = [
'#markup' => $this
->t('Global and entity tokens are replaced with their values.'),
];
$token_types = [];
$parameters = $this->routeMatch
->getParameters();
foreach ($parameters as $parameter) {
$entity_type = NULL;
if ($parameter instanceof ContentEntityInterface) {
$entity_type = $parameter
->getEntityTypeId();
}
elseif ($parameter instanceof ConfigEntityBundleBase) {
$entity_type = $parameter
->getEntityType()
->getBundleOf();
}
if (isset($entity_type)) {
$token_type = $this->tokenEntityMapper
->getTokenTypeForEntityType($entity_type);
$token_types[] = $token_type;
}
}
$build[] = [
'#prefix' => ' ',
'#theme' => 'token_tree_link',
'#token_types' => $token_types,
];
return $this->renderer
->render($build);
}