Overrides Drupal\Core\Entity\EntityFormController::prepareForm().
Overrides EntityFormController::prepareEntity
protected function prepareEntity() {
  // Determine the displays available for editing.
  if ($tabs = $this
    ->getDisplayTabs($this->entity)) {
    // If a display isn't specified, use the first one.
    if (empty($this->displayID)) {
      foreach ($tabs as $id => $tab) {
        if (!isset($tab['#access']) || $tab['#access']) {
          $this->displayID = $id;
          break;
        }
      }
    }
    // If a display is specified, but we don't have access to it, return
    // an access denied page.
    if ($this->displayID && !isset($tabs[$this->displayID])) {
      throw new NotFoundHttpException();
    }
    elseif ($this->displayID && (isset($tabs[$this->displayID]['#access']) && !$tabs[$this->displayID]['#access'])) {
      throw new AccessDeniedHttpException();
    }
  }
  elseif ($this->displayID) {
    throw new NotFoundHttpException();
  }
}