protected function generateRestLinks(EntityInterface $entity) {
    $rest_resource_config_storage = $this->entityTypeManager->getStorage('rest_resource_config');
    $entity_type = $entity->getEntityType()->id();
    $rest_resource_config = $rest_resource_config_storage->load("entity.$entity_type");

    $current_format = $this->requestStack->getCurrentRequest()->query->get('_format');

    $links = [];
    $route_name = $this->routeMatch->getRouteName();

    if ($rest_resource_config) {
      $formats = $rest_resource_config->getFormats("GET");

      foreach ($formats as $format) {
        if ($format == $current_format) {
          continue;
        }

        switch ($format) {
          case 'json':
            $mime = 'application/json';
            break;

          case 'jsonld':
            $mime = 'application/ld+json';
            break;

          case 'hal_json':
            $mime = 'application/hal+json';
            break;

          case 'xml':
            $mime = 'application/xml';
            break;

          default:
            continue;
        }

        $meta_route_name = "rest.entity.$entity_type.GET";

        $route_params = [$entity_type => $entity->id()];

        if (!$this->accessManager->checkNamedRoute($meta_route_name, $route_params, $this->account)) {
          continue;
        }

        $meta_url = Url::fromRoute($meta_route_name, $route_params)
          ->setAbsolute()
          ->toString();

        $links[] = "<$meta_url?_format=$format>; rel=\"alternate\"; type=\"$mime\"";
      }
    }

    return $links;
  }