0

I want to create a new paragraph item to a user bundle. This is the code:

$name = "Test";
$userdata = user_load($user->uid);
$paragraph = entity_create('paragraphs_item', array('field_name' => 'field_userdata', 'bundle' => 'userdata'));
$paragraph->setHostEntity('user', $userdata);
$paragraph->field_name[LANGUAGE_NONE][0]['value'] = $name;
$paragraph->save();

But nothing happens, no errors, no new entity.. Are there differences to adding to a node bundle?

Thank you!

1 Answer 1

0

First make sure following things are configured properly:

  1. Is Entity API module is enabled in your site?
  2. Have you enabled Logging and errors from admin/config/development/logging page, to see site errors?
  3. In second line you have not defined $user object, are you defined else where?
  4. How are you calling this function?

If everything is configured properly then execute following code:

$name = "Test";
global $user;
$userdata = user_load($user->uid);
$paragraph = entity_create('paragraphs_item', array('field_name' => 'field_userdata'));
$paragraph->setHostEntity('user', $userdata);
$paragraph->field_name[$userdata->language][]['value'] = $name;
$entity->save();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.