Skip to content

Create a paragraphs field programmatically

Laryn edited this page Jul 15, 2024 · 2 revisions

Here is another example that worked for me:

  • Paragraph type: my_paragraph
  • Paragraph field on node: field_paragraph_field
  • Simple text field on paragraph entity: field_simple_text
$n = node_load(239);
$p = entity_create('paragraphs_item', array('bundle' => 'my_paragraph', 'field_name' => 'field_paragraph_field'));
$p->is_new = TRUE;
$p->setHostEntity('node', $n);
$p->field_simple_text[LANGUAGE_NONE][0]['value'] = 'what what';
$p->save();

Source: daggerhart

Clone this wiki locally