I've installed contact storage module, it's provide storage for Contact messages which are fully-fledged entities in Drupal 8. What I want to do, is to insert data programmatically from my custom module into the entity of the contact storage
1 Answer
Yep. Just use any of the methods available to create the entity and save it.
use Drupal\contact\Entity\Message;
$message = Message::create([
// And other fields required...
'subject' => 'Subject',
'message' => 'Message...',
'recipient' => 1,
]);
$message->save();
-
Thanks so much, but when I used this, I got this error Missing bundle for entity type contact_message in Drupal\Core\Entity\ContentEntityStorageBase->doCreate() Commented May 17, 2017 at 10:09
-
It's solved now, it was missing the bundle type, thanks so much john Commented May 17, 2017 at 10:19
-
-
1@Hugo I've added bundle type before required fields like this
Message::create([ 'contact_form' => 'feedback', 'subject' => '.......', 'name'=> ......, 'mail' => ..........., 'message' => '......', ]);
Commented May 18, 2017 at 12:10