Closed (fixed)
Project:
Paragraphs
Version:
8.x-1.0-rc4
Component:
Documentation
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
15 Apr 2016 at 10:58 UTC
Updated:
16 Mar 2023 at 12:34 UTC
Jump to comment: Most recent
Comments
Comment #2
killua99 commentedWhat I know is, now paragraphs on Drupal 8 use entity_reference_revisions maybe you want to take a look in there.
Check how entity_reference_revisions link the paragraphs with the entity who is using it. Remember not only Content Type could use paragraphs.
Comment #3
derMatze commentedMeanwhile I found a solution:
First create the paragraph, than add the paragraph to the corresponding node/entity.
Comment #4
arla commentedThat indeed looks like the standard way to do it.
You can also use appendItem and/or pass the entire Paragraph entity as the value:
Comment #6
vijaycs85Thanks @derMatze for raising this issue and the solution... landing here from google search :)
Comment #7
bkeller commentedLanded here from Google as well, and had to modify a bit to get it to work for my purposes.
I'm using paragraphs with just a text field and an optional image, and a node can have multiple paragraphs attached.
Maybe this will help someone else...
Comment #8
nitin.k commentedPlease use below namespace..
Comment #9
ben.hamelin#7 worked for me
Drupal core 8.3.7
Paragraphs 8.x-1.0
Comment #10
couloir007 commented#7 works as well as appendItem except for when I open the node and save it I get this:
8.4.2
Comment #11
couloir007 commentedScratch that. I'm feeling like an idiot. I was accidentally adding the wrong paragraph type. It added, but I guess it didn't like it.
Comment #12
miststudent2011 commentedHere is a better example :
Source :
https://stackoverflow.com/a/48399547/
Comment #13
sibopa commentedThe #12 here have limitation in case you have an unlimited number of items to add. #7 will work better. Thanks!
Comment #14
sadikyalcin commentedHere is a more efficient way for unlimited and nested paragraphs. Note: you do not need to save the paragraphs when creating a new node; the relationship will be assigned automatically.
Credit to '4k4' on Stack: Source
Comment #15
ahaomar commentedI want to create Paragraph types can you some one guide me how can i create via programming
Comment #16
dorficus commented@ahaomar the issue queue probably isn't the best place to be asking that. There is the forum section of Drupal.org and/or Drupal Answers. It's more likely that someone will see your question there and have time to answer rather than in the issue queue where the focus is on specific issues within projects.
With that being said, I suggest looking at the code for Paragraph.php and see how the base paragraph is created then maybe looking at a module that extends paragraphs like Bootstrap Paragraphs and see how those are built so that you can get a starting point.
Comment #18
xandermar commentedWorkable in Drupal 9
Comment #19
mxr10_ commentedHi team,
I'm having some issues trying to save some field using paragraphs,
Where i run my code happen this:
The first field has value and second is empty
and the next block the first field is empty and second has value
screenshoot
This is my code:
I don't know what to do to fill both field
Could you please help me?
Regards
Mario
Comment #20
ressaI was looking for a way to create a new node, and populate a multi-value Paragraphs field, and found this issue. I didn't find the solution here, but finally figured it out so here it is:
Comment #21
oakulm commentedSorry to raise old issues but this keeps popping in Google. You should not include references to concrete classes ie. Paragraph but should use service injection:
Same goes with Node.