Prevent submission of duplicate content in Drupal 8
Context
We have a location entity (content type) which is referenced from other content (Programs, Organizations, Events, Places) on service providers on the Find It platform can re-use and share locations. Typing in addresses and zip codes is no one’s favorite thing.
But asking people to search before adding is only so effective. How do we prevent ending up with hundreds of duplicate locations?
Research
Very old post but with an answer that almost stays relevant: https://www.drupal.org/forum/support/post-installation/2010-01-23/how-can-i-prevent-duplicate-nodes-before-posting
https://www.drupal.org/project/unique_field is indeed a great module, unfortunately it doesn’t seem fully ported to Drupal 8.
It allows preventing duplicates (during validation, after submit is pressed) by validating a single field or comparing multiple fields.
(A similar module, which puts warnings in the user interface before submission, is https://www.drupal.org/project/unique_field_ajax — but it only works on one field at a time, as far as i can tell.)
Ideally, though, we do warn people as they are adding and let them pick the content they’re duplicating from a list.
Anti-Duplicates module operates only on the node title, which is a good start.
Unfortunately, our use case involves auto-generating the title from the other fields (especially the compound address field), so anti-duplicates as it currently stands is not helpful. Probably is the best module to build on, though.
Update: OK, Anti-Duplicates has some weak points:
- Works on all content types— not configurable to only act on specific ones
- Interrupts tabbing out of the title field (flashes “Looking for duplicates” and your cursor ends up back at the end of the title rather than advancing to the next field you were ready to start writing in.)
- Was accidentally created as a distribution project not a module project so composer can’t install it properly, https://www.drupal.org/project/anti_duplicates/issues/2896471
Note: You do have to move the form element for the duplicate listing somewhere near the title for this to be reasonable, but it’s actually really cool that’s configurable.
Investigation continues in 2021
- drupal 8 find duplicate content
Suggest Similar Titles | Drupal.org
Intelligent Content Tools | Drupal.org
https://opensenselabs.com/blog/tech/use-drupal-intelligent-content-tools-module
Places to report back to
See also
2019-09-12-clean-up-duplicate-content-or-other-entities-by-merging-them.md