How can I understand when a node is being edited or viewed? I want to add a class to the body to distinguish the node's view page from the edit page.

In classy you have 'page-node-type-' ~ node_type|clean_class. I'd like to add page-node-type-' ~ node_type|clean_class ~ '-edit' if we're on the edit page, but I can't figure out what that if statement would have in its condition.

Which code should I use to add that class only when a node is being edited?
In this case you'd want to look at parts of the url. The easiest way to do that would be passing in additional classes from a preprocess function in the .theme file, and by looking at the URL path:

$current_path = \Drupal::service('path.current')-&gt;getPath();
$path_args = explode('/', $current_path);

if ($path_args[0] == 'node' &amp;&amp; $path_args[2] == 'edit') {
  // add classes
}


This would be similar to using the arg() function from previous versions.