When having multiple forms on the same page with identical element ID, comments do not load for the forms other than the first one

Created on 4 February 2025, 3 months ago

Problem/Motivation

Hello. We are using the comments feature provided by this module. We have a page with multiple entity forms loaded. The comments work only for the first form. The other ones don't have them loaded neither saved.

Steps to reproduce

  1. Prepare an entity type / bundle (e.g. a term) with a formatted field with a text format that allows comments.
  2. Create multiple instances from their respective edit form.
  3. Have a controller that includes multiple entity forms loaded by the standard entity form builder.
    1. => The comments for the first form work as expected.
    2. => The comments for the second form do not load. They do not save either even when comments are contributed.

Proposed resolution

The gist is to fix the commentsAdapter.js to support multiple form structure.

The problem lies mainly here (taken from the /build minified version because I have tested with this file):

        const e = this.editor.plugins.get("CommentsRepository"),
          t = this.editor.plugins.has("RealTimeCollaborativeComments"),
          o = document.querySelector(this.storage.getSourceDataSelector("comments"));

By using document.querySelector, the script gets the first instance of the comments-data textarea.

As the forms share the same field ID, they share the same elementId. The querySelector is then not enough accurate.

I propose this change:

        const e = this.editor.plugins.get("CommentsRepository"),
          t = this.editor.plugins.has("RealTimeCollaborativeComments"),
          o = this.editor.sourceElement.closest(".js-form-wrapper").querySelector(this.storage.getSourceDataSelector("comments"));

Other places in this module could be updated in a similar approach (revisionHistory, trackChanges, etc.) to support multiple forms in the same page.

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Active

Version

1.3

Component

Plugin: Comments

Created by

🇫🇷France dakwamine

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

Comments & Activities

Production build 0.71.5 2024