Created
July 19, 2017 04:41
-
-
Save kythanh/e29a2100a3da25cbd7a62fdea167e29f to your computer and use it in GitHub Desktop.
Programmatically create Paragraph entity in Drupal8
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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(), | |
) | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
use Drupal\paragraphs\Entity\Paragraph; // Don't forget to use a little Class...