diff --git a/includes/webform.editor.inc b/includes/webform.editor.inc index 83dc2f011..c48fac1ae 100644 --- a/includes/webform.editor.inc +++ b/includes/webform.editor.inc @@ -228,11 +228,10 @@ function _webform_delete_file_usage(array $uuids, $type, $id, $count) { /******************************************************************************/ /** - * Parse an HTML snippet for any linked file with data-entity-uuid attributes. + * Parse text for any linked files with data-entity-uuid attributes. * * @param string $text - * The partial (X)HTML snippet to load. Invalid markup will be corrected on - * import. + * The text to parse. * * @return array * An array of all found UUIDs. @@ -245,24 +244,21 @@ function _webform_parse_file_uuids($text) { } $uuids = []; - // Get all images using a regex. - if (preg_match_all('/]+>/', $text, $matches)) { - foreach ($matches[0] as $img) { + + // Look through all images and hyperlinks for files. + if (preg_match_all('/<(img|a)[^>]+>/', $text, $matches)) { + foreach ($matches[0] as $match) { // Cleanup quotes escaped via YAML. // Please note, calling stripslashes() twice because elements are // double escaped. - $img = stripslashes(stripslashes($img)); - - // Create a DomElement so that we can parse the image's attributes. - $dom_node = Html::load($img)->getElementsByTagName('img')->item(0); - - // Get the entity type and uuid. - $type = $dom_node->getAttribute('data-entity-type'); - $uuid = $dom_node->getAttribute('data-entity-uuid'); - - // Check the image is a file entity with a uuid. - if ($type === 'file' && $uuid) { - $uuids[] = $uuid; + $match = stripslashes(stripslashes($match)); + + // Look for a file and record UUID when found. + $dom = Html::load($match); + $xpath = new \DOMXPath($dom); + $nodes = $xpath->query('//*[@data-entity-type="file" and @data-entity-uuid]'); + if (count($nodes)) { + $uuids[] = $nodes->item(0)->getAttribute('data-entity-uuid'); } } }