Add in a synonyms feature

Created on 16 March 2022, almost 3 years ago
Updated 6 August 2024, 7 months ago

Hi all,

I use glossify on multiple Drupal websites at my job. A while ago my team on one of these sites requested a feature to add synonyms to our site's glossary, and asked that a synonym be glossifiable without need for creating a whole new entry in the glossary. They asked that the node title be considered the core term, parent term, however you'd like to call it, and that that node have a list of strings that could be used interchangeably with the parent term. Whichever term first appears in an article, either parent or synonym, that should be the only instance of that term to be glossified.

For example: A hypothetical content type named Glossary Item has 3 fields - Title (string), Body (string), Synonyms (array(string)). On my example website, I have a node of content type Glossary Item with the title set as "President of the United States". There is one string object in the Synonyms array, and that Synonym string is set as "POTUS".

With my patch, both "President of the United States" and "POTUS" are candidates to be glossified. Since my sites require only the first found match be glossified, if one term is glossified then the other will not be, regardless of which one occurs first.

One of my projects just requested I port that feature to the new site, so I took the time to go in, clean it up a bit, and make it glossify-2.0.1,compatible and I thought it would be worthwhile to post on Drupal.org in case any other developers might find this useful. A few things to note:

  • For the feature to work, the synonyms field MUST have the machine name `field_synonym`.
  • I added an update hook to glossify.install to auto-generate that field, but in order for the field to be auto-generated, there MUST exist a content type with the word "glossary" in its machine name. I could not figure out how to make this configurable in the time I had to port and improve the feature, but maybe someone else can.
  • I did not go in and test how this feature works when glossifying ALL instances of a term. Both of my projects' requirements state that we only glossify the first instance of any term on a page, so I didn't take the time (read: use our budget) to test that aspect. Rest assured it works fine if you only want to glossify the first instance of a term or its synonym.
  • The patchfile also includes a statement to force glossify to ignore th and h1-6 header tags.
  • This patchfile also goes in and updates the to-be-deprecated calls to render() with \Drupal::service('renderer')->render()

This patchfile is really meant to serve more as a guide than as a plug and play feature, but I thought it would be useful nonetheless.

✨ Feature request
Status

Needs review

Version

2.0

Component

Code

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡ΈUnited States yospyn

    Resurfacing this feature request for v3 if possible. Very similar need (see screenshot), except I'm using glossify_taxonomy instead of node:

    - Have a term such as President of the United States
    - Create field_acronym plain text field for same taxonomy, then enter POTUS into that field
    - Glossify would treat either the name or field_synonym equally, applying to whichever appears first on a page

    Great module! We're using it with the book module as a glossary of terms, which display as pop-ups on hover.

  • πŸ‡ΈπŸ‡³Senegal diaodiallo

    Hello, I am sharing a patch I refactored for my colleague @yospyn.

    As mentioned @yospyn we have synonyms in a term field which need to be called 'field_synonym' (Just add this field and your synonyms to use the patch).

    Thanks to @JakeAPoe for the patch I used it for this version 3 patch.

  • Status changed to Needs work 6 months ago
  • πŸ‡©πŸ‡ͺGermany Anybody Porta Westfalica

    I'd like this very much. I think it should allow to select a certain field with a list of synonyms from the source entity.

    Please use MRs instead of patches!

  • πŸ‡©πŸ‡ͺGermany Anybody Porta Westfalica

    Raising the priority and hope someone finds the time for the implementation!

  • πŸ‡΅πŸ‡ΉPortugal joao.ramos.costa

    joao.ramos.costa β†’ made their first commit to this issue’s fork.

  • First commit to issue fork.
  • Merge request !35Resolve #3269949 "Synonyms" β†’ (Open) created by prudloff
  • Pipeline finished with Success
    18 days ago
    Total: 145s
    #415897
  • Pipeline finished with Success
    16 days ago
    Total: 142s
    #417667
  • Merge request !40Resolve #3269949 "Add synonyms" β†’ (Open) created by Unnamed author
  • Pipeline finished with Success
    16 days ago
    Total: 327s
    #417692
  • πŸ‡«πŸ‡·France prudloff Lille

    prudloff β†’ changed the visibility of the branch 3269949-synonyms to hidden.

  • Pipeline finished with Success
    11 days ago
    Total: 151s
    #422143
Production build 0.71.5 2024