protected function FormatterManager::processData in RESTful 7.2
Helper function to get a formatter and apply a method.
Parameters
string $method: A valid method to call on the FormatterInterface object.
array $data: The array of data to process.
string $formatter_name: The name of the formatter for the current resource. Leave it NULL to use the Accept headers.
Return value
string The processed output.
2 calls to FormatterManager::processData()
- FormatterManager::format in src/
Formatter/ FormatterManager.php - Call the output format on the given data.
- FormatterManager::render in src/
Formatter/ FormatterManager.php - Call the output format on the given data.
File
- src/
Formatter/ FormatterManager.php, line 136 - Contains \Drupal\restful\Formatter\FormatterManager
Class
- FormatterManager
- Class FormatterManager.
Namespace
Drupal\restful\FormatterCode
protected function processData($method, array $data, $formatter_name = NULL) {
if ($resource = $this->resource) {
$request = $resource
->getRequest();
}
else {
$request = restful()
->getRequest();
}
$accept = $request
->getHeaders()
->get('accept')
->getValueString();
$formatter = $this
->negotiateFormatter($accept, $formatter_name);
$output = ResourceManager::executeCallback(array(
$formatter,
$method,
), array(
$data,
$formatter_name,
));
// The content type header is modified after the massaging if there is
// an error code. Therefore we need to set the content type header after
// formatting the output.
$content_type = $formatter
->getContentTypeHeader();
$response_headers = restful()
->getResponse()
->getHeaders();
$response_headers
->add(HttpHeader::create('Content-Type', $content_type));
return $output;
}