Last active
May 9, 2020 13:05
-
-
Save dreambubbler/a89b9ac5ff34facd60fc7d4c8afecc9b to your computer and use it in GitHub Desktop.
Revisions
-
dreambubbler revised this gist
Apr 11, 2017 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -13,7 +13,7 @@ */ // Example 1: attaching a single term $node = \Drupal\node\Entity\Node::load($nid); // Attach only one term $tid = 1; // The ID of the term to attach. @@ -22,7 +22,7 @@ // End of Example 1 /> // Example 2: attaching multiple terms $node2 = \Drupal\node\Entity\Node::load($nid2); // To attach multiple terms, the term IDs must be in an array. $multiple_tids = array(1, 2, 3); // Each is Term ID of an existing term. -
dreambubbler revised this gist
Apr 11, 2017 . 1 changed file with 6 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -6,25 +6,26 @@ * Must know: * - field_example_name: the full name of the term reference field * - tid: the term ID(s) to attach * * Keep in mind that this example uses Node::load() * but you can use any Entity::load() * e.g. User::load(), Term::load(), etc. */ // Example 1: attaching a single term $node = Node::load($nid); // Attach only one term $tid = 1; // The ID of the term to attach. $node->set('field_example_name', $tid); $node->save(); // End of Example 1 /> // Example 2: attaching multiple terms $node2 = Node::load($nid2); // To attach multiple terms, the term IDs must be in an array. $multiple_tids = array(1, 2, 3); // Each is Term ID of an existing term. $node2->set('field_example_name', $multiple_tids); // Note that field_example_name must allow multiple terms. $node2->save(); // End of Example 2 /> -
dreambubbler created this gist
Apr 11, 2017 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,30 @@ <?php use Drupal\node\Entity\Node; /** * Before attaching a term(s) to a term reference field, * Must know: * - field_example_name: the full name of the term reference field * - tid: the term ID(s) to attach */ // Example 1: attaching a single term // Work with a full node object. $node = Node::load($nid); // Attach only one term $tid = 1; // The ID of the term to attach. $node->set('field_example_name', $tid); $node->save(); // End of Example 1 // Example 2: attaching multiple terms // Work with a full node object. $node2 = Node::load($nid2); // To attach multiple terms, the term IDs must be in an array. $multiple_tids = array(1, 2, 3); // Each is Term ID of an existing term. $node2->set('field_example_name', $multiple_tids); // Note that field_example_name must allow multiple terms. $node2->save(); // End of Example 2