I was using menu_get_object()
to load node information in Drupal 6.
if ($node = menu_get_object()) {
// Get the nid
$nid = $node->nid;
}
Since menu_get_object()
is deprecated in Drupal 8, I was using the following code.
if ($node_id = \Drupal::request()->attributes->get('node')) { #menu_get_object()
//load all the information of the node
$node = node_load($node_id);
}
echo '<pre>';print_r($node);exit();echo '</pre>'; //its okay
echo $node->type->value; //not working
This is not getting the node values, but printing the node information's in array. How do I resolve this ?
UPDATE
I am getting all other values like $node->title->value
and $node->nid->value
, but not $node->type->value
.