-
Testing Tokens with Entity Ref Traversal via Drush
I am working on a project that has some complicated depth. I needed a way to quickly test token replacement. It’s pretty simple when you understand a few things.
Example Architecture
Here’s the Drupal architecture for this example:
- Discussion Group (content type)
- Title
- Intro
- Body
- “Associated Experts” paragraph field (allows one “Associated Experts” paragraph item)
- Associated Experts (paragraph type, used by many content types like Discussion Group above)
- Heading
- Intro
- Experts (allows unlimited number of “Expert” nodes)
- Expert (content type)
- Title
- Photo
- Discussion Group (content type)
-
Adding Entity Wrapper Class from Field Value using Display Suite
NOTICE: This works fine in Drupal 7. For Drupal 8 please note: https://www.drupal.org/node/2863420
This may not work with paragraph bundles (because you don’t have a Token view mode). Maybe there’s a way, but I don’t have time to mess with it.
Sometimes as a developer you need to provide your Drupal authors with the ability to choose different variations of a particular content object. For example, imagine you have a Callout paragraph bundle and you want the author to choose between a Dark or a Light colorscheme; if the user chooses Light, the font colors appear dark over a light background. To achieve this you need a dark or light class on the entity wrapper based on whichever the author chose; this would let you write CSS to target each color scheme. Using Display Suite this is an easy problem to solve and doesn’t require any preprocess code or other hand-coded solution.
This solution requires Token and Display Suite. You will need to enable the ui modules from these, as well as ds_extras to give you the CSS class functionality.
-
Adding a Custom Token to the Ubercart (before version 2.3) Email Templates
This tutorial is for Ubercart versions earlier than version 2.3. There is a newer version of this example for Ubercart 2.3 or later.
In this post I’ll show how to set up an extra token for use in an Ubercart template. This will require creating a custom module (because we don’t really want to modify others’ modules). We’ll use a few different hooks to create the token, and then simply modify the template to include this token. This setup requires the token module (which is required by Ubercart), so make sure this is enabled!
-
Adding a Custom Token to the Ubercart (version 2.3 or newer) Email Templates
This tutorial is for Ubercart versions later than version 2.3. If you’re using an older version of Ubercart, you’ll want to see this example. This example is very similar, but accommodates the changes made to the template system in Ubercart.
In this post I’ll show how to set up an extra token for use in an Ubercart template. This will require creating a custom module (because we don’t really want to modify others’ modules). We’ll use a few different hooks to create the token, and then modify the template (or create a new template) to include this token. This setup requires the token module (which is required by Ubercart), so make sure this is enabled!