Populating a CKEditor field on form build

Created on 8 April 2025, 14 days ago

Problem/Motivation

I am fairly confident with ECA and do quite a bit with it so I am not a complete beginner.

I am trying to pre-populate a bog-standard Long text field with some HTML - essentially I am trying to prepopulate the CKEditor widget.

The bigger picture is that I am actually trying to clone one Long text field from one node entity and stuff it into a Long text field on a new node form.

I know how to get my hands on both the original node's field value and the format and I can easily perform this kind of clone operation when my target node get inserted (or updated) into the database, but I want more than that, I want to see the field populated on the node edit form.

It's not for want of reading documentation and ploughing through (pretty untrustworthy/fruitless AI-generated ideas) but I just cannot seem to get anywhere because, according to the documentation, I need to target the form element by name but the bit where you 'type' into a CKEditor input ain't quite what it seems :-0

Can anyone please help point me in the right direction?

Thanks

💬 Support request
Status

Active

Version

2.1

Component

Documentation

Created by

🇬🇧United Kingdom SirClickALot Somerset

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

Comments & Activities

  • Issue created by @SirClickALot
  • 🇬🇧United Kingdom SirClickALot Somerset

    I don't know if this is 'right' and I'd like to keep this issue open for advise from others bit in the meantime, we have been able to use a neat 'trick' to populate a node edit form with Long text (CKEDitor) the fields.

    We fire up a node edit form and pick up URL query string using a token: [current-page:query:original_question_id]

    For example, firing up a new node form linked to an original...

    /node/add/long_answer_response?original_question_id=8724

    We process query string using an ECA Build form event.

    We also use an ECA Insert content entity event to copy various field's contents from the original to the target node.

    The real trick is in the steps labelled (1) and (2) where we force a node save in the Build form event which then triggers the second event to populate the fields and then we do a sneaky redirection back to the node form and everything is magically all there in place.

    Here is an illustration of the logic if helps anyone else out...

  • 🇩🇪Germany jurgenhaas Gottmadingen

    I'm refusing to review processing issues in screenshots, it's just not telling enough detail of what's going on.

    But I can tell that CKEditor widgets are not playing nice with anything in Drupal. Doing a save in a form build and then redirecting sounds terrible. But maybe you can use the Prepare content entity form event, and instead of trying to modify the form field, you can set field values of the entity token. Drupal will build the form afterwards and then use the values from the entity which will have been altered at that point. So, this should then use your injected values in the to be built form and all should be fine.

  • 🇬🇧United Kingdom SirClickALot Somerset

    OK, very interesting

    ...Doing a save in a form build and then redirecting sounds terrible.

    ... is exactly what we after because it was either nifty and smart idea or the not as it seems!

    It was the voice of experience we were looking for ;-)

    We did have an initial go with the Prepare content entity form but were no sure if that was the right approach, but now we'll venture forth.

  • 🇩🇪Germany jurgenhaas Gottmadingen

    OK, let's keep this open so that you can feed back if it actually works for you as expected. You can then mark it as fixed.

Production build 0.71.5 2024