1

I have a content type 'supertest' with fields 'Category' and 'Section' (both are taxonomy terms reference, dropdowns). And every user has a 'Display name' custom field.

And I need to update title of nodes (of this content type) on every node save, desired format is '[category] - [section]: [author.display_name]'.

I've tried to add a rule (in Rules module) - actions 'Display message' (just to test) on 'Before content save', but it doesn't work. And I can't figure out how to set category field value to title.

How can I make rules to change title of a node in my drupal 8 site?

  • Can you this on After saving new content event. You need to create two rules .First for save new content and second for updating content. – Pankaj Yogi Jul 25 '18 at 13:00
  • One thing you cannot set node title as your desired format because rules Data selector not allow to do that. – Pankaj Yogi Jul 25 '18 at 13:12
  • 2
    This would be easy enough to do in code, considering Rules has no stable release. – Kevin Jul 25 '18 at 13:18
  • I've updated the question title once again to get to the root of the problem. If you find that it doesn't match your problem, please change it back :) – leymannx Jul 25 '18 at 21:59
  • @PankajYogi I take you created the demo with simplytest.me, didn't you? In that case, it's worth remembering the site will be deleted in 12/24 hours. (I bet the second, but I don't recall it right now.) – kiamlaluno Jul 26 '18 at 9:26
0

The answer is very easy to accomplish by just following the below steps.

First of all, with all my respect to the glory of the Rules modules but yet it is not ready for development on Drupal 8 Website otherwise you will be facing tons of issues and you will spend most of your time within the issue page.

So, here comes the Business rules, the alternative workflowing D8 module.

What is Business rules module:

The Business Rules module is inspired on Rules module and allow site administrators to define conditionally actions execution based on events. It's based on variables and completely build for Drupal 8.
This module has a fully featured user interface to completely allow the site administrator to understand and create the site business rules. It's also possible to extend it by creating new ReactsOn Events, Variables, Actions and Conditions via plugins.

I strongly advice you to read the documentation, so you get more familiar with it.

Why using Business rules modules ?

Business rules modules will not only help you to achieve your above question but will give your website a powerful way to execute actions based on events and conditions defined by you as administrator.

Using and getting familiar with such great module, will save you spending time trying to create a custom module to add some extra features to your website while you can do it with few clicks using Business Rules modules.

How to auto-generate the title based on node's fields values after saving the node:

1) Install and Enable the:

  • Business rules Module.

  • Dbug Module. (Dependency for business rules module)

  • Token Module. (Specific for your case)

2) Goto: /admin/config/workflow/business_rules/collection

3) Under the Actions Tab, Click on +Add Action

4) Type: Set Field Value

5) Here is where the magic will happen: - Label: Change the Title field based on other field values.

  • Description: Action to Change the Title field based on other field values.

  • Target Entity Type: Content

  • Target Bundle: Supertest

  • Field: Text (Plain): Title [Title]

  • Value: [node:category:entity:name] - [node:section:entity:name] - [node:author]

  • Save the action

6) Goto: /admin/config/workflow/business_rules/collection

7) Under the Rules Tab, Click on +Add Rule

8) Reacts on event: Before Saving Entity

  • Label: Before saving entity of type node (supertest)

  • Description: Before saving entity of type node (supertest)

  • Target Entity Type: Content

  • Target Bundle: Supertest

  • In the Items Section: Click on add action link.

  • Popup window will open: Click on the desired action's title to add it to your current rule. (In your case, there is only one action available so click on its title)

  • Save the Rule

Testing the rule:

1) Goto: /node/add/superset

2) Title: This title should change after saving this node

3) Set your taxonomy fields as desired

4) Save the node.

5) Check your new title.

Voila!

Feel free to ask for help if you faced some troubles.

1

Could be a job for Automatic Entity Label. Actually I'm using it that way – in production (though it has no stable release yet it works just fine).

"Automatic Entity Label" is a small and efficient module that allows hiding of entity label fields. To prevent empty labels it can be configured to generate the label automatically by a given pattern.

You can define tokens from which the title will be built. An you can optionally set the title field to be always hidden on the node form. I'd also recommend to make the fields mandatory (required) that you use to build the title.

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.