public function TokenCustomController::add in Custom Tokens 8
Displays add custom token links for available types.
Parameters
\Symfony\Component\HttpFoundation\Request $request: The current request object.
Return value
array A render array for a list of the custom token types that can be added or if there is only one custom token type defined for the site, the function returns the custom token add page for that custom token type.
1 string reference to 'TokenCustomController::add'
File
- src/
Controller/ TokenCustomController.php, line 68
Class
- TokenCustomController
- Controller for token_custom entity.
Namespace
Drupal\token_custom\ControllerCode
public function add(Request $request) {
$types = $this->tokenCustomTypeStorage
->loadMultiple();
if ($types && count($types) == 1) {
$type = reset($types);
return $this
->addForm($type, $request);
}
if (count($types) === 0) {
return [
'#markup' => $this
->t('You have not created any token types yet. Go to the <a href=":url">token type creation page</a> to add a new token type.', [
':url' => Url::fromRoute('token_custom.type_add')
->toString(),
]),
];
}
return [
'#theme' => 'token_custom_add_list',
'#content' => $types,
];
}