Skip to content

Instantly share code, notes, and snippets.

@kythanh
Created July 19, 2017 04:41
Show Gist options
  • Save kythanh/e29a2100a3da25cbd7a62fdea167e29f to your computer and use it in GitHub Desktop.
Save kythanh/e29a2100a3da25cbd7a62fdea167e29f to your computer and use it in GitHub Desktop.
Programmatically create Paragraph entity in Drupal8
$paragraph = Paragraph::create([
'type' => 'paragraph_type_name',
'field_text' => array(
"value" => '...content...',
"format" => "full_html"
),
]);
$paragraph->save();
$node = entity_load('node', $nid);
$node->field_content = array(
array(
'target_id' => $paragraph->id(),
'target_revision_id' => $paragraph->getRevisionId(),
)
);
@mogbril
Copy link

mogbril commented Dec 20, 2020

use Drupal\paragraphs\Entity\Paragraph; // Don't forget to use a little Class...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment