function EditorHooks::parseFileUuids

Parse an HTML snippet for any linked file with data-entity-uuid attributes.

Parameters

string $text: The partial (X)HTML snippet to load. Invalid markup will be corrected on import.

Return value

array An array of all found UUIDs.

1 call to EditorHooks::parseFileUuids()
EditorHooks::getFileUuidsByField in core/modules/editor/src/Hook/EditorHooks.php
Finds all files referenced (data-entity-uuid) by formatted text fields.

File

core/modules/editor/src/Hook/EditorHooks.php, line 478

Class

EditorHooks
Hook implementations for editor.

Namespace

Drupal\editor\Hook

Code

protected function parseFileUuids(string $text) : array {
  $dom = Html::load($text);
  $xpath = new \DOMXPath($dom);
  $uuids = [];
  foreach ($xpath->query('//*[@data-entity-type="file" and @data-entity-uuid]') as $node) {
    $uuids[] = $node->getAttribute('data-entity-uuid');
  }
  return $uuids;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.