A website I maintain can't view revisions without receiving an unexpected error. The log file points to this code in the .theme file but I have no idea what it does. When I commented it out, the website seems to function fine and revisions are viewable.
function themename_preprocess_page(&$variables) {
$current_path = \Drupal::service('path.current')->getPath();
$path_args = explode('/', $current_path);
$node = \Drupal::routeMatch()->getParameter('node');
if($node) {
$node_info = \Drupal\node\Entity\Node::load($node->id());
if($node_info->hasField('field_component')) {
$paragraph = $node_info->field_component->getValue();
if($paragraph) {
foreach ( $paragraph as $element ) {
$p = \Drupal\paragraphs\Entity\Paragraph::load( $element['target_id'] );
}
$variables['hero_banner'] = $p;
}
}
}
}
The log particularly points to the 6th line above as the error. It mentions "Error: Call to a member function id()".
Does anyone have any clue? Thanks!