1

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
  • 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
    Commented May 16, 2017 at 17:37

1 Answer 1

4

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();
4
  • 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
  • @MohamedOsamaGbril What did you have for the bundle?
    – Hugo
    Commented May 18, 2017 at 10:54
  • 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

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.