Skip to content

Instantly share code, notes, and snippets.

@josephdickson
Last active July 15, 2022 21:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save josephdickson/5178979b3b67c3cc14c84f3ff33746de to your computer and use it in GitHub Desktop.
Save josephdickson/5178979b3b67c3cc14c84f3ff33746de to your computer and use it in GitHub Desktop.
yearonly token patch
diff --git a/yearonly.module b/yearonly.module
index c3ad6f3..bc9bc33 100644
--- a/yearonly.module
+++ b/yearonly.module
@@ -28,3 +28,26 @@ function yearonly_help($route_name, RouteMatchInterface $route_match) {
return $output;
}
}
+
+/**
+ * Implements hook_token_info_alter().
+ *
+ * This adds the missing token info for automatically detected tokens.
+ */
+
+function yearonly_token_info_alter(&$info) {
+ $entities = \Drupal::service('entity_field.manager')->getFieldMap();
+ foreach ($entities as $entity_key => $entity) {
+ foreach ($entity as $field_key => $field) {
+ if ($field['type'] !== 'yearonly' ) {
+ continue;
+ }
+
+ $token_key = sprintf($entity_key . '-%s', $field_key);
+ $info['tokens'][$token_key]['value'] = [
+ 'name' => t('Year Only'),
+ 'description' => t('Year only value.'),
+ ];
+ }
+ }
+}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment