Skip to content

Instantly share code, notes, and snippets.

@bratsun
Created October 11, 2016 08:41
Show Gist options
  • Save bratsun/15f7a8da58b3f65444b9d4c4acbab69a to your computer and use it in GitHub Desktop.
Save bratsun/15f7a8da58b3f65444b9d4c4acbab69a to your computer and use it in GitHub Desktop.
// create and save
$entity = Entity::create($values);
$entity = Entity::load($id);
$entities = Entity::loadMultiple($ids);
$entity->save();
$entity->delete();
$entity_id = $entity->id();
$bundle = $entity->bundle();
// load and perform operations or get data
$node = $this->entityTypeManager
->getStorage('node')
->load($nid);
$node = Node::load($nid);
$node->save();
$node->delete();
$node_type = $node->getType();
$title = $node->getTitle();
$visible = $node->isPublished();
$node->setPromoted(TRUE);
$uid = $node->getOwnerId();
$author = $node->getOwner();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment