Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@lincoln-chawora
Last active January 10, 2020 18:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lincoln-chawora/a5e2db23c1240f1ad267bcd998c4a8f5 to your computer and use it in GitHub Desktop.
Save lincoln-chawora/a5e2db23c1240f1ad267bcd998c4a8f5 to your computer and use it in GitHub Desktop.
How load a node in drupal 8
$route_name = \Drupal::routeMatch()->getRouteName();
if ($route_name == 'entity.node.canonical') {
node = \Drupal::routeMatch()->getParameter('node');
$node_type = $node->getType();
$title = $node->getTitle();
$visible = $node->isPublished();
$node->setPromoted(TRUE);
$uid = $node->getOwnerId();
// $author will be user object of the person who created the node.
$author = $node->getOwner();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment