В предыдущей статье говорилось о том как работать с токенами, где были описаны простые варианты. Продолжим о более сложных, а именно следующие два:
- 
    создание группы токенов; 
  
- 
    добавление группы токенов в сущестующую группу; 
  
Создание группы токенов
Здесь достаточно объявить тип токена и наполнить его токенами.
<?php
/**
 * Implements hook_token_info().
 */
function example_token_info() {
  // Объявляем тип продукта.
  $types['special-product'] = array(
    'name' => t('Special products'),
    'description' => t('List of products related to the current user'),
    // Этот параметр говорит о том, какие данные нужны для работы токена.
    'needs-data' => 'user',
  );
  // Наполняем группу токенами, относящимися к типу special-product.
  $tokens['special-product']['check-product:?'] = array(
    'name' => t('User has product'),
    'description' => t('Creates link to purchase ANY product in case if' .
      ' signed in user has no the product, show flag that the product' .
      ' is purchased otherwise.'),
  );
  return array(
    'types' => $types,
    'tokens' => $tokens,
  );
}
Теперь в созданную группу очень легко можно вкладывать другие группы токенов.

Делается очень легко:
<?php
/**
 * Implements hook_token_info().
 */
function example_token_info() {
  $types['special-product'] = array(
    'name' => t('Special products'),
    'description' => t('List of products related to the current user'),
    'needs-data' => 'user',
  );
  $tokens['special-product']['check-product:?'] = array(
    'name' => t('User has product'),
    'description' => t('Creates link to purchase ANY product in case if' .
      ' signed in user has no the product, show flag that the product' .
      ' is purchased otherwise.'),
  );
  // При необходимости можно вложить группу токенов типа user.
  $tokens['special-product']['user'] = array(
    'name' => t('List of user tokens'),
    'description' => t('All tokens related to user, for example.'),
     // говорит о том, что этот токен типа user,
     // а тип user, в свою очередь, тоже группа токенов. 
    'type' => 'user' 
  );
  return array(
    'types' => $types,
    'tokens' => $tokens,
  );
}
Добавление группы токенов в существующую группу
Для того чтобы вложить только что созданную группу токенов в другую группу. Например, в current-user, нужно совсем немного изменить код.
<?php
/**
 * Implements hook_token_info().
 */
function example_token_info() {
  $types['special-product'] = array(
    'name' => t('Special products'),
    'description' => t('List of products related to the current user'),
    'needs-data' => 'user',
  );
  $tokens['special-product']['check-product:?'] = array(
    'name'        => t('User has product'),
    'description' => t('Creates link to purchase ANY product in case if'
      . ' signed in user has no the product, show flag that the product'
      . ' is purchased otherwise.'),
  );
  // Перемещаем нашу группу токенов в другую группу (user).
  $tokens['user']['special-products'] = array(
    'name' => t('Current user products'),
    'description' => t('List of products related to the current user'),
    'type' => 'special-product',
  );
  return array(
    'types' => $types,
    'tokens' => $tokens,
  );
}