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
$new_term = \Drupal\taxonomy\Entity\Term::create([ | |
'vid' => 'example_vocabulary_machine_name', | |
'name' => 'Example term name', | |
]); | |
$new_term->enforceIsNew(); | |
$new_term->save(); |
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; | |
/** | |
* 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 | |
* | |
* Keep in mind that this example uses Node::load() |
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\user\Entity\User; | |
// Updating a user is a three step process: | |
// 1) load the user object to change | |
// 2) set property/field to new value | |
// 3) Save the user object. | |
// This example updates: | |
// 1) password |