Skip to content

Create a paragraphs field programmatically

Laryn - CEDC.org edited this page Jan 4, 2019 · 2 revisions

This requires the entity_metadata_wrapper module. In D7 the entity_save() function comes with the entity module, but in Backdrop that function doesn't exist outside of the entity_metadata_wrapper module.

With that module installed, the code should basically be the same. 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