Last active
July 15, 2022 21:12
-
-
Save josephdickson/5178979b3b67c3cc14c84f3ff33746de to your computer and use it in GitHub Desktop.
yearonly token patch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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