- Issue created by @apmsooner
- @apmsooner opened merge request.
- Status changed to Needs review
over 1 year ago 7:01pm 20 March 2023 - Status changed to Needs work
about 1 year ago 8:39am 21 September 2023 - πͺπ¨Ecuador jwilson3
$properties['raw_data'] = DataDefinition::create('string') ->setLabel(t('Raw data')) ->setDescription(t('The svg raw xml data.')) ->setClass('\Drupal\svg_image_field\SvgRawComputed') ->setSetting('file source', 'entity') ->setComputed(TRUE) ->setInternal(FALSE);
If the underlying request here is to improve this for JSONAPI, then it seems like we should also provide metadata containing the URL to the SVG file, so that a decoupled frontend consumer can have the choice to render the SVG inline or via an IMG tag, or is that somehow already available?
if (!empty($svg_file)) { $dom->loadXML($svg_file); $svg_data = $dom->saveXML(); $svgSanitizer = new Sanitizer(); $svgSanitizer->removeRemoteReferences(TRUE); $svgSanitizer->removeXMLTag(TRUE); $svg_data = $svgSanitizer->sanitize($svg_data); return $svg_data; }
This section probably needs to respect other existing configurations for inline SVG configurations. Note that we already have
SVGImageFieldFormatter::loadInlineSvgData()
for this purpose. So the question is whether field formatters are in play for the JSONAPI stuff. I.e., can this code either be modified to load the settings from a configured display formatter, or refactored entirely to just call the loadInlineSvgData() function? - πΊπΈUnited States rrrob
If the underlying request here is to improve this for JSONAPI, then it seems like we should also provide metadata containing the URL to the SVG file, so that a decoupled frontend consumer can have the choice to render the SVG inline or via an IMG tag, or is that somehow already available?
The path to the SVG file is not removed, so it can still be used as an image like you mentioned. This patch just adds the raw svg code inline.
There is one issue though. I do see the following in the Drupal log:
Deprecated function: Creation of dynamic property Drupal\svg_image_field\SvgRawComputed::$value is deprecated in Drupal\Core\TypedData\TypedData->setValue() (line 102 of /var/www/html/web/core/lib/Drupal/Core/TypedData/TypedData.php)
If I add an empty
setValue
function in theSvgRawComputed
class, the deprecation error goes away:/** * {@inheritdoc} */ public function setValue($value, $notify = TRUE) { // Do nothing, as we don't need to set the value directly }