This will walk you through how to re-write a taxonomy's url alias with an anchor ('#') (on creation or save), which will work with a views glossary view of taxonomy terms.
Go to `/admin/config/workflow/eca` and create a "New Model", this will be our canvas to work with.
- First things first, lets give our model a name, so on the right side of your screen, you will find your details palate, (which we will refer later also).
- General --> Name: Taxonomy url alias
Now click the "Save" button at the top of your screen"
- Drag and drop "Create StartEvent" (the circle from the palate on the left), This will be our "Event to fire on" That will tell eca when to activate our code.
- Template: Pre-save content entity
Next we will add create a task for our code to do.
Click on our circle on our canvas, and you will see a small pop-up palete that contains a few items. Drag and drop the square or "Append Task" on to your canvas.
- The first task is to remove "the, an, a" from the name so it sorts correctly. While clicked on your new "Task" (the square we just placed), fill in the following options
- General -- > Name: remove ('A', 'An' and 'The')
- Template: Tamper find replace regex
- Custom Properties -- > Data to be Tampered: `[term:name]`
- Custom Properties -- > REGEX to find: `/^(The|An|A)\\s+/`
- Custom Properties -- > Result token name: `[taxonomy_url_remove_an]`
Drag another "Append Task" onto your canvas.
Now we are going to move all text to lowercase since it is a url
- General --> Name: lowercase
- Template: Tamper convert case
- Custom Properties -- > Data to be tampered: `[taxonomy_url_remove_an]`
- Custom Properties -- > How to convert case: Convert to lowercase
- Custom Properties -- > Result token name: `[taxonomy_url_lowercase]`
Drag another "Append task" onto your canvas.
Since this is a url we need to remove characters that don't parse in a url for this we will use regex again
- General -- > Name: remove
- Template: Tamper find replace regex
- Custom Properties -- > Data to be Tampered: `[taxonomy_url_lowercase]`
- Custom Properties -- > REGEX to find: `/\[^a-zA-Z0-9\\s\]/`
- Custom Properties -- > Result token name: `[taxonomy_url_remove]`
Drag another "Append task" onto your canvas.
Since this is for a url, we need to replace the spaces with dashes.
- General -- > Name: replace
- Template: Tamper find replace regex
- Custom Properties -- > Data to be Tampered: `[taxonomy_url_remove]`
- Custom Properties -- > REGEX to find: `/(\\s|(\\s)\\1+)+/`
- Custom Properties -- > Result token name: `[taxonomy_url_replace]`
Now we need to truncate the term to one letter so that it will work with views glossary setting.
- General -- > Name: truncate
- Template: Tamper truncate
- Custom Properties -- > Data to be Tampered: `[taxonomy_url_replace]`
- Custom Properties -- > Number of characters: 1
- Custom Properties -- > Result token name: `[taxonomy_url_trun]`
Now we need to set that target field, which is "URL alias" on the term edit form.
- General -- > Name: set field
- Template: Entity set field value
- Custom Properties -- > Field name: path
- Custom Properties -- > Field value: `/[taxonomy_url_trun]#[taxonomy_url_replace]`
Now when a term is created or saved, the url alias to written for you!