Last active
March 22, 2016 16:36
-
-
Save djevans/0705aef99cbdd51ea63f to your computer and use it in GitHub Desktop.
Setting multi-valued reference fields programmatically in Drupal 8.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Drupal\node\Entity\Node; | |
// node 1 has 'field_ref', which is a multi-valued field currently referencing nodes 2 and 3. | |
$node = Node::load(1); | |
$node->field_ref[] = 4; | |
$node->save(); // 'field_ref' now contains [2,3,4]. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment