Add new Paragraph items in an existing content Form

Created on 23 February 2023, almost 2 years ago
Updated 24 February 2023, almost 2 years ago

Problem/Motivation

I would like to add a new paragraph item into the node but I don't know which action should I use to do that. What I would like to do is to edit existing node, the ECA will check if data is provided in URL, if yes, then, add a new paragraph item in which all the field inside paragraph will be prefilled by the data from URL. User can just check if data is filled correctly and click save manually. (I can do the Prefill data part for newly created content. This part should be similar.)

Is this possible with ECA?

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

💬 Support request
Status

Fixed

Version

1.1

Component

Code

Created by

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

Comments & Activities

  • Issue created by @abx
  • 🇩🇪Germany jurgenhaas Gottmadingen

    Yes, this can be done. Starting with the Prepare content entity form event, which is triggered before the entity edit form is being built. Then you can check all your URL parameters with the Request: Get URL query parameter action and if necessary, you can then create a new paragraph entity with Entity: create new. Finally, add that new paragraph entity to your node that's being prepared for editing, and Drupal will then build the form accordingly.

  • Thank you for quick reply. However, the last part of your instruction is what I'm still trying to figure it out.

    I omit the part "Request: Get URL query parameter" for now. I just want to click Edit the node and then, the new additional paragraph form in that node appear for me to fill in.

    I tried "List: add entity" , "Render : Add Entity Form" but none of that work.

  • 🇩🇪Germany jurgenhaas Gottmadingen

    You should use Entity: set field value with Save entity set to no.

  • I got a new paragraph add into an existing content with "Entity: set field value". However, the new paragraph is in collapse state. What should I do to make that new paragraph default to open for Edit?

    Thank you,

  • 🇩🇪Germany jurgenhaas Gottmadingen

    With this approach, we alter the entity which is then given to the form. So, at that point, we don't have access to the form. You may be able to adjust your form settings for entity field in your Drupal site.

    Otherwise you may have to add another even listening to the form build and then make some adjustments to the field there.

  • I'm sorry if I ask a lot but I have another question about Prefill item from URL. For now, after I use "Entity: create new.", I use action "Entity: set field value" to set each field value before I use "Entity: set field value" again to set this newly created paragraph attach to the main content. Everything seems to work fine with fixed value but if I want to use [current-page:query:xxx], this will not work.

    I saw that you instruct me to use "Request: Get URL query parameter", how can I work with that? I have tested it with blank "Query parameter name" and set token as "pretime". URL query is "?paidtime=1300?paiddate=2023-02-10" When, I try to display message of token "pretime" below is what I got:

    [pretime] display as paidtime: '1300?paiddate=2023-02-10'
    [pretime:paidtime] display as 1300?paiddate=2023-02-10
    [pretime:paiddate] display as [pretime:paiddate]

    How can I make use of multiple parameter with this token?

  • Ok, this is my bad. The URL query should be in this format ?paidtime=1300&paiddate=2023-02-10 and once I did that, I can get each value from each parameter by using [current-page:query:xxx] or Request: Get URL query parameter

    Thank you,

  • jurgenhaas, is there any different to set value between Form field: set default value and Entity: set field value (Set and clear previous value)?

    With Build Form Event, I use Form field: set default value and it works with Time field without any problem. But with this approach, I use Entity: set field value but I can never be able to set time on that Time field. (Same field, Same Token setting.)

    When I try to set time as 13:00 ( Tried using value from Fixed Value, Request: Get URL query parameter and [current-page:query:xxx] ) What I got is always 12:00:13AM. When set to 1:00 / 1:12, I got 12:00:01 AM.

  • I found that Time Field keep data in unix timestamp. So, in order to use Entity: set field value, I have to convert data into unix timestamp.

  • Status changed to Fixed almost 2 years ago
  • 🇩🇪Germany jurgenhaas Gottmadingen

    Sounds like you managed to answer all your recent questions yourselves. This is great and I'm closing this issue as being fixed. If new questions come up, it would be recommended to open individual issues for each question, as this will then also easier for others to follow or to find solutions if anyone comes along looking for advise.

  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024