/** * @return array */ function yourmodule_token_info() { return [ 'types' => [ 'your-token-name' => [ 'name' => t('Settings'), 'description' => t('...'), ], ], 'tokens' => [ 'your-token-name' => [ 'your_token_name-1' => [ 'name' => t('...'), 'description' => t('...'), ], 'your_token_name-2' => [ 'name' => t('...'), 'description' => t('...'), ], ], ], ]; } /** * @param $type * @param $tokens * @param array $data * @param array $options * @param \Drupal\Core\Render\BubbleableMetadata $bubbleable_metadat * * @return array */ function yourmodule_tokens($type, $tokens, array $data, array $options, BubbleableMetadata $bubbleable_metadat) { $replacements = []; $sanitize = !empty($options['sanitize']); switch ($type) { case 'your-token-name': $replacements['[your_token_name-1]'] = '...'; $replacements['[your_token_name-2]'] = '...'; break; } return $replacements; }
カスタムモジュールからtokenを提供する方法(drupal8版)
OTHER FAQ
カテゴリ | Core Ver. | 関連モジュール | タイトル |
---|---|---|---|
言語 | 7.15 | Entity Translation | 各フィールドのラベルの多言語切り替え漏れ(フィールド・ラベル) |
言語 | 7.15 | Entity Translation | nodeのEntity Translation |
言語 | 7.15 | Language | まだ翻訳されていない英語文、どうにかならない? |
言語 | 7.14 | Entity Translation | 各フィールドのラベルの多言語切り替え漏れ(接頭子、接尾子) |
言語 | 6.22 | URLエイリアスを使った場合に、翻訳したページで同じURLエイリアスが使えないという不具合 | |
言語 | 7.28 | vim | vimで全角が化けてしまう |
開発 mail | 7.50 | Mail Safety | 開発/テスト用サイトのメール |