bratsun
10/11/2016 - 8:41 AM

Complete entity routing and operations (http://wizzlern.nl/sites/wizzlern.nl/files/artikel/drupal-content-entity-8.0.pdf)

// 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();