Last active
September 23, 2017 15:46
-
-
Save alexd73/189c2d9b67283160b8a7d570a5c07572 to your computer and use it in GitHub Desktop.
drupal 8: Node and fields manipulation
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 characters
// clone node programmatically | |
$node = \Drupal\node\Entity\Node::load($nid); | |
if ($node) { | |
$cloned_node = $node->createDuplicate(); | |
$cloned_node->save(); | |
} |
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 characters
$nids = \Drupal::entityQuery('node')->condition('type','menu_item')->execute(); | |
$nodes = \Drupal\node\Entity\Node::loadMultiple($nids); |
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 characters
foreach ($nodes as $node) { | |
$node->set("field_menu_category", [ | |
['target_id' => $tid] | |
]); | |
$node->save(); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment