You are here

public function RestResourceConfig::getFormats in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/rest/src/Entity/RestResourceConfig.php \Drupal\rest\Entity\RestResourceConfig::getFormats()

Retrieves a list of supported response formats.

Parameters

string $method: The request method e.g GET or POST.

Return value

string[] A list of supported format IDs.

Overrides RestResourceConfigInterface::getFormats

File

core/modules/rest/src/Entity/RestResourceConfig.php, line 172

Class

RestResourceConfig
Defines a RestResourceConfig configuration entity class.

Namespace

Drupal\rest\Entity

Code

public function getFormats($method) {
  switch ($this->granularity) {
    case RestResourceConfigInterface::METHOD_GRANULARITY:
      return $this
        ->getFormatsForMethodGranularity($method);
    case RestResourceConfigInterface::RESOURCE_GRANULARITY:
      return $this->configuration['formats'];
    default:
      throw new \InvalidArgumentException('Invalid granularity specified.');
  }
}