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

  • Sounds straightforward enough, where are you stuck? What does your code so far look like? Please edit it into the question so we can get an idea of the problem – Clive May 16 '17 at 17:37

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,
  • 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() – Mohamed Osama Gbril May 17 '17 at 10:09
  • It's solved now, it was missing the bundle type, thanks so much john – Mohamed Osama Gbril May 17 '17 at 10:19
  • @MohamedOsamaGbril What did you have for the bundle? – Hugo May 18 '17 at 10:54
  • 1
    @Hugo I've added bundle type before required fields like this Message::create([ 'contact_form' => 'feedback', 'subject' => '.......', 'name'=> ......, 'mail' => ..........., 'message' => '......', ]); – Mohamed Osama Gbril May 18 '17 at 12:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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