class FormatterSingleJson in RESTful 7.2
Class FormatterSingleJson @package Drupal\restful\Plugin\formatter
Plugin annotation
@Formatter(
id = "single_json",
label = "Single JSON",
description = "Output a single item using the JSON format."
)
Hierarchy
- class \Drupal\restful\Plugin\formatter\Formatter extends \Drupal\Component\Plugin\PluginBase implements FormatterInterface uses ConfigurablePluginTrait
- class \Drupal\restful\Plugin\formatter\FormatterJson implements FormatterInterface
- class \Drupal\restful\Plugin\formatter\FormatterSingleJson
- class \Drupal\restful\Plugin\formatter\FormatterJson implements FormatterInterface
Expanded class hierarchy of FormatterSingleJson
File
- src/
Plugin/ formatter/ FormatterSingleJson.php, line 22 - Contains \Drupal\restful\Plugin\formatter\FormatterSingleJson.
Namespace
Drupal\restful\Plugin\formatterView source
class FormatterSingleJson extends FormatterJson {
/**
* Content Type
*
* @var string
*/
protected $contentType = 'application/drupal.single+json; charset=utf-8';
/**
* {@inheritdoc}
*/
public function prepare(array $data) {
// If we're returning an error then set the content type to
// 'application/problem+json; charset=utf-8'.
if (!empty($data['status']) && floor($data['status'] / 100) != 2) {
$this->contentType = 'application/problem+json; charset=utf-8';
return $data;
}
$extracted = $this
->extractFieldValues($data);
$output = $this
->limitFields($extracted);
// Force returning a single item.
$output = ResourceFieldBase::isArrayNumeric($output) ? reset($output) : $output;
return $output ?: array();
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ConfigurablePluginTrait:: |
protected | property | Plugin instance configuration. | |
ConfigurablePluginTrait:: |
public | function | ||
ConfigurablePluginTrait:: |
public | function | 1 | |
ConfigurablePluginTrait:: |
public | function | ||
ConfigurablePluginTrait:: |
public | function | ||
Formatter:: |
protected | property | The resource handler containing more info about the request. | |
Formatter:: |
protected static | function | Gets a cache fragments based on the data to be rendered. | |
Formatter:: |
protected | function | Helper function that calculates the number of items per page. | |
Formatter:: |
protected | function | Gets a cache controller based on the data to be rendered. | |
Formatter:: |
public | function |
Formats the un-structured data into the output format. Overrides FormatterInterface:: |
|
Formatter:: |
protected | function | Gets the cached computed value for the fields to be rendered. | |
Formatter:: |
protected | function | Gets the cached computed value for the fields to be rendered. | |
Formatter:: |
public | function |
Gets the underlying resource. Overrides FormatterInterface:: |
|
Formatter:: |
protected | function | Checks if the passed in data to be rendered can be cached. | |
Formatter:: |
protected static | function | Helper function to know if a variable is iterable or not. | |
Formatter:: |
protected | function | Returns only the allowed fields by filtering out the other ones. | |
Formatter:: |
protected | function | Gets the cached computed value for the fields to be rendered. | |
Formatter:: |
public | function |
Sets the underlying resource. Overrides FormatterInterface:: |
|
Formatter:: |
protected static | function | Given a prefix, return the allowed fields that apply removing the prefix. | |
Formatter:: |
public | function | ||
FormatterJson:: |
protected | function | Add HATEOAS links to list of item. | |
FormatterJson:: |
protected | function | Extracts the actual values from the resource fields. | |
FormatterJson:: |
public | function |
Returns the content type for the selected output format. Overrides Formatter:: |
|
FormatterJson:: |
public | function |
Parses the body string into the common format. Overrides Formatter:: |
|
FormatterJson:: |
public | function |
Renders an array in the selected format. Overrides FormatterInterface:: |
|
FormatterSingleJson:: |
protected | property |
Content Type Overrides FormatterJson:: |
|
FormatterSingleJson:: |
public | function |
Massages the raw data to create a structured array to pass to the renderer. Overrides FormatterJson:: |