0

There is a similar post in stackoverflow, but it is very old, and It is not exactly the same question: how-to-make-contents-title-unique

I was trying to create a webpage as a Wiki. I began to work with MediaWiki but finally I changed to Drupal.

The idea is that the title of every Drupal node (independently of the content type created) has to be unique. I mean, There will not be aa identical title in the table "node" of Drupal.

One way to do this is to create a primary key in the column "title" of the table "node"; but modify the schema structure of Drupal always is not a good option

title column in node table

Other option is to use a module. I have found two of them:

This is very old and it is not on maintain: Unique field

And this one is better: Unique Content Title, the problem with this is that says that "Content title will be unique for each content type" Unique Content Title

And I need that would be unique independently of the content type. Every node title has to be different, independently of the content type.

Do you know what could be the best choice?

Thank you in advance!

jorge_vicente
  • 358
  • 1
  • 5
  • 15

1 Answers1

1

I would go for custom solution.

Use hook_form_alter() to set custom submit handler for node edit form (because it's too late to cancel node saving in hook_node_presave() ):

https://api.drupal.org/comment/51923#comment-51923

So inside your submit handler check the submitted node title, search if there is another node with that title and if there is set some error and forbid successful form submission.

MilanG
  • 6,994
  • 2
  • 35
  • 64