Unexpected error when trying to view revisions 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(&amp;$variables) {  
  $current_path = \Drupal::service('path.current')-&gt;getPath();
  $path_args = explode('/', $current_path);
  $node = \Drupal::routeMatch()-&gt;getParameter('node');
  if($node) {
    $node_info = \Drupal\node\Entity\Node::load($node-&gt;id());
    if($node_info-&gt;hasField('field_component')) {
      $paragraph = $node_info-&gt;field_component-&gt;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!
You need to add a check and also no need to $node_info = Node::load as the node is already loaded. The first two lines inside the function are not even getting used, so I removed them.

function themename_preprocess_page(&amp;$variables) {  
  $node = \Drupal::routeMatch()-&gt;getParameter('node');
  if ($node instanceof \Drupal\node\NodeInterface) { // check it's a node
    if($node-&gt;hasField('field_component')) {
      $paragraph = $node-&gt;field_component-&gt;getValue();
      if($paragraph) {
        foreach ( $paragraph as $element ) {
          $p = \Drupal\paragraphs\Entity\Paragraph::load( $element['target_id'] );
        }
        $variables['hero_banner'] = $p;
      }
    }
  }
}