How do I get the content type of a node entity from the $entity object?
If you know that you have a node, then you can use getType(). If you don't know that, you can use he generic method -&gt;bundle(). Note that the second will return the entity type in case of an entity type that doesn't have bundles, like users.

Again, my standard reference to http://wizzlern.nl/sites/wizzlern.nl/files/artikel/drupal-content-entity-8.0.pdf, it contains both methods.