class FormatterHalXml in RESTful 7.2
Class FormatterHalXml @package Drupal\restful\Plugin\formatter
Plugin annotation
@Formatter(
id = "hal_xml",
label = "HAL+XML",
description = "Output in using the HAL conventions and XML format.",
curie = {
"name": "hal",
"path": "doc/rels",
"template": "/{rel}",
},
)
Hierarchy
- class \Drupal\restful\Plugin\formatter\Formatter extends \Drupal\Component\Plugin\PluginBase implements FormatterInterface uses ConfigurablePluginTrait
- class \Drupal\restful\Plugin\formatter\FormatterHalJson implements FormatterInterface
- class \Drupal\restful_example\Plugin\formatter\FormatterHalXml implements FormatterInterface
- class \Drupal\restful\Plugin\formatter\FormatterHalJson implements FormatterInterface
Expanded class hierarchy of FormatterHalXml
File
- modules/
restful_example/ src/ Plugin/ formatter/ FormatterHalXml.php, line 28 - Contains \Drupal\restful\Plugin\formatter\FormatterHalJson.
Namespace
Drupal\restful_example\Plugin\formatterView source
class FormatterHalXml extends FormatterHalJson implements FormatterInterface {
/**
* Content Type
*
* @var string
*/
protected $contentType = 'application/xml; charset=utf-8';
/**
* {@inheritdoc}
*/
public function render(array $structured_data) {
return $this
->arrayToXML($structured_data, new \SimpleXMLElement('<api/>'))
->asXML();
}
/**
* Converts the input array into an XML formatted string.
*
* @param array $data
* The input array.
* @param \SimpleXMLElement $xml
* The object that will perform the conversion.
*
* @return \SimpleXMLElement
*/
protected function arrayToXML(array $data, \SimpleXMLElement $xml) {
foreach ($data as $key => $value) {
if (is_array($value)) {
if (!is_numeric($key)) {
$subnode = $xml
->addChild("{$key}");
$this
->arrayToXML($value, $subnode);
}
else {
$subnode = $xml
->addChild("item{$key}");
$this
->arrayToXML($value, $subnode);
}
}
else {
$xml
->addChild("{$key}", htmlspecialchars("{$value}"));
}
}
return $xml;
}
}
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:: |
public | function |
Parses the body string into the common format. Overrides FormatterInterface:: |
2 |
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 | ||
FormatterHalJson:: |
protected | function | Add HATEOAS links to list of item. | |
FormatterHalJson:: |
constant | |||
FormatterHalJson:: |
protected | function | Extracts the actual values from the resource fields. | |
FormatterHalJson:: |
public | function |
Returns the content type for the selected output format. Overrides Formatter:: |
|
FormatterHalJson:: |
protected | function | Checks if the current plugin has a defined curie. | |
FormatterHalJson:: |
public | function |
Massages the raw data to create a structured array to pass to the renderer. Overrides FormatterInterface:: |
|
FormatterHalJson:: |
protected | function | Prefix a property name with the curie, if present. | |
FormatterHalXml:: |
protected | property |
Content Type Overrides FormatterHalJson:: |
|
FormatterHalXml:: |
protected | function | Converts the input array into an XML formatted string. | |
FormatterHalXml:: |
public | function |
Renders an array in the selected format. Overrides FormatterHalJson:: |