function _swagger_ui_formatter_get_svg_definition in Swagger UI Field Formatter 8.2
Gets Swagger UI related SVG definition.
Since Swagger UI v3.13.4 there is no need to include the <svg> tag in HTML.
Return value
string|null The required <svg> tag as a HTML string or NULL if it doesn't exist.
See also
https://github.com/swagger-api/swagger-ui/releases/tag/v3.13.4
1 call to _swagger_ui_formatter_get_svg_definition()
- SwaggerUIFormatterTrait::buildRenderArray in src/
Plugin/ Field/ FieldFormatter/ SwaggerUIFormatterTrait.php - Builds a render array from a field.
File
- ./
swagger_ui_formatter.module, line 153 - Main module file for Swagger UI Field Formatter.
Code
function _swagger_ui_formatter_get_svg_definition() {
if ($cache = \Drupal::cache()
->get(SWAGGER_UI_FORMATTER_SVG_DEFINITION_CID)) {
return $cache->data;
}
$library_path = _swagger_ui_formatter_get_library_path();
if ($library_path && file_exists(DRUPAL_ROOT . $library_path . '/dist/index.html')) {
$dom_crawler = new Crawler(file_get_contents(DRUPAL_ROOT . $library_path . '/dist/index.html'));
$dom_crawler = $dom_crawler
->filterXPath('descendant-or-self::body/svg');
if ($domElement = $dom_crawler
->getNode(0)) {
$svg = $domElement->ownerDocument
->saveHTML($domElement);
\Drupal::cache()
->set(SWAGGER_UI_FORMATTER_SVG_DEFINITION_CID, $svg);
return $svg;
}
}
return NULL;
}