Last active
January 9, 2017 11:37
-
-
Save DuaelFr/a03202e6e28dbc4838c0e95c23ae3c3a to your computer and use it in GitHub Desktop.
Preset paragraph on node creation
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
<?php | |
use Drupal\node\Entity\Node; | |
/** | |
* Implements hook_ENTITY_TYPE_create(). | |
*/ | |
function my_module_node_create(Node $node) { | |
if ($node->bundle() == 'my_bundle') { | |
$field = $node->get('field_my_paragraph_field'); | |
if ($field->isEmpty()) { | |
$paragraphs = \Drupal::entityTypeManager()->getStorage('paragraph')->create([ | |
'type' => 'my_paragraph_type', | |
]); | |
$field->appendItem($paragraphs); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment