Taxonomy url alias with an anchor¶
This will walk you through how to re-write a taxonomy's url alias with an anchor ('#') (on creation or save). For this example we will use movie "gCinema (genre)" taxonomy.
We need to add two fields to our taxonomy term at "/admin/structure/taxonomy/manage/cinema_genre/overview/fields"
All fields will be "plain text" "simple text". Name the fields:
field_cinema_g_name_html, and field_cinema_g_name_node_view.
Now 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: Cinema (genre) Now click the "Save" button at the top of your screen"
-
Drag and drop "Create StartEvent" (the circle from the palette 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 palette that contains a few items. Drag and drop the square or "Append Task" on to your canvas.
This task we are going to fill the field_cinema_g_name_node_view field that we created in our taxonomy term.
- General --> Name: set field value
- Template: Entity: set field value
- Custom properties --> Field name: field_cinema_g_name_node_view
- Custom properties --> Field value: [term:name]
(the reason we move the term name directly to the text field because in drupal using the term name in views and other systems is a bit tough, but a text field all system support)
Click on the circle again and add another task. This task chain will fill the field_cinema_g_name_html field we created on our taxonomy term.
(the first event in this chain is to replace the spaces with dashes)
- General --> Name: replace
- Template: Tamper: find replace regex
- Custom properties --> Data to be tampered: [term:name]
- Custom properties --> Regex to find: /[\s]/
- Custom properties --> Replacement pattern: -
- Custom properties --> Result token name: [cinema_g_name_html_replace]
While clicked on the square, use the small pop-up and add a task.
(now we need to take our resulting string from the above task and turn it all lowercase)
- General --> Name: lowercase
- Template: Tamper convert case
- Custom properties -- > Data to be tampered: [cinema_g_name_html_replace]
- Custom properties -- > How to convert case: Convert to lowercase
- Custom properties -- > Result token name: [cinema_g_name_html_lower]
While clicked on the square, use the small pop-up and add a task.
(we now need to set the value of field_cinema_g_name_html)
- General --> Name: set field value
- Template: Entity: set field value
- Custom properties --> Field name: field_cinema_g_name_html
- Custom properties --> Field value: [cinema_g_name_html_lower]
Now click on the circle again and add another task.
(we need to set the value of the url alias of our taxonomy term)
- General --> Name: replace
- Template: Tamper: find replace regex
- Custom properties --> Data to be tampered: [term:name]
- Custom properties --> Regex to find: /[\s]/
- Custom properties --> Replacement pattern: -
- Custom properties --> Result token name: [cinema_g_path_replace]
While clicked on the square, use the small pop-up and add a task.
(now we need to take our resulting string from the above task and turn it all lowercase)
- General --> Name: lowercase
- Template: Tamper convert case
- Custom properties -- > Data to be tampered: [cinema_g_path_replace]
- Custom properties -- > How to convert case: Convert to lowercase
- Custom properties -- > Result token name: [cinema_g_path_lower]
While clicked on the square, use the small pop-up and add a task.
(we now need to set the value of field_cinema_g_name_html)
- General --> Name: set field value
- Template: Entity: set field value
- Custom properties --> Field name: path
- Custom properties --> Field value: [cinema_g_path_lower]