public function Kml::encode in farmOS 2.x
Overrides XmlEncoder::encode
File
- modules/
core/ kml/ src/ Encoder/ Kml.php, line 27
Class
- Kml
- Provides a KML encoder that extends from the XML encoder.
Namespace
Drupal\farm_kml\EncoderCode
public function encode($data, $format, array $context = []) {
// Build XML document to encode.
$xml = [
'@xmlns' => 'http://earth.google.com/kml/2.1',
'Document' => [
'Placemark' => $data,
],
];
// Provide default context for the KML format.
$xml_context = [
'xml_version' => '1.0',
'xml_encoding' => 'UTF-8',
'xml_format_output' => TRUE,
'xml_root_node_name' => 'kml',
] + $context;
// Encode using the XML encoder.
return $this
->getBaseEncoder()
->encode($xml, 'xml', $xml_context);
}