Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By mxr10_ on
Hi 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:
<?php
$paragraph_1 = Paragraph::create([
'type' => 'field_from_paragraph',
'field_item_1' => "abcdefghijk",
]);
$paragraph_icon->save();
$paragraph_2 = Paragraph::create([
'type' => 'field_from_paragraph',
'field_item_2' => "123456789",
]);
$paragraph_beneficio->save();
$node = Node::create([
'type' => 'items',
'field_from_content_type' => array(
array(
'target_id' => $paragraph_1->id(),
'target_revision_id' => $paragraph_1->getRevisionId()
),
array(
'target_id' => $paragraph_2->id(),
'target_revision_id' => $paragraph_2->getRevisionId()
),
),
]);
I don't know what to do to fill both field
Could you please help me?
Regards
Mario
Comments
1. What is the use case?
1. What is the use case?
2. Where do you run this code, is this a hook or controller?
Also you may try this:
Hi @wombatbuddy thank you for
Hi @wombatbuddy thank you for, that help me so much now i can add those field correctly.
1. I'm trying to add some items from a xml file.
2. I've created a custom module and i have a controller where is this code,
But now i have another issue trying to add some translation for paragraphs,
This is my code:
When i run this controller english and spanish have the same value, "english abcdefg" and "english 1234567",
But if i create a content type manually i can add diferent translation for spanish
Could you please help me?
How can i add a translation for paragraphs?
Regards
Mario
You may try this recipe:
You may try this recipe: https://drupal.stackexchange.com/a/300197
Hi @wombatbuddy, than you for
Hi @wombatbuddy, than you for your answer,I tried to implement that code but i can't get it, I'll keep going searching for an answer
When i run this controller
What do "english" and "spanish" mean in your context? Do you want to create a node with two translation or what? Could you please explain your goal one more time?
Adding multiple values to a paragraph field
I was also looking for a way to cycle through a multidimensional array, and save them in a multi-value paragraph field, and found this issue. I finally found a solution, and shared it in #2707017-20: How to create paragraphs item programmatically in D8?.