Q: drupal 8 how to create nodes with multiple values I'm creating a message-system, where you can write with other users. My problem is to write a message to multiple users. I created a custom field to store the receiver of the messages and a field to store if the user read the message or not. But how do I store multiple values to my custom field via delta? (Or is there maybe a way to store the uid as delta? Would be easier for me.)
This is now:

Should be like this:
.
Here is my code to create my message (node):
public function submitForm( array &$form, FormStateInterface $form_state ) {
    $language = \Drupal::languageManager()->getCurrentLanguage()->getId();
    // The messagetext.
    $message = $form_state->getValue('message');
    // Use WYSIWYG or not
    $format = ( is_array( $message ) ? $message['format'] : 'basic_html' );
    $message = ( is_array( $message ) ? $message['value'] : '<p>' . $message . '</p>');

    // read = 0 -> unread
    // read = 1 -> read
    $read = 0

    $newMessage = Node::create([
        'type' => 'msg_message',
        'bundle' => 'msg_message',
        'langcode' => $language,
        'uid' => (int)$form['senderId'],
        'title' => $form_state->getValue('subject'),
        'status' => 1,
        'promote' => false,
        'created' => $form['timestamp'],
        'changed' => $form['timestamp'],
        'body' => [
            'summary' => '',
            'value' => $message,
            'format' => $format,
        ],
        'field_msg_receiver' => [
            'value' => json_encode($form_state->getValue('receiverId')),
        ],
        'field_msg_read' => [
            'value' => $read
        ],
    ]);

    $newMessage->save();

    $form_state->setRedirect('message_system.message_overview.all');
}


A: See How to set value for multivalue field in drupal 8 programmatically.
I tried marking this as a duplicate, but that's only allowed if on the same site.  The other question is on Drupal Answers, not Stack Overflow.
