You are here

public function ContentHubEntityEmbedHandler::getReferencedUuids in Acquia Content Hub 8

Method to parse UUID from text.

Parameters

string $text: Any html text.

Return value

array Array with parsed Uuids.

File

src/ContentHubEntityEmbedHandler.php, line 39

Class

ContentHubEntityEmbedHandler
Content Hub Entity Embed Handler Class.

Namespace

Drupal\acquia_contenthub

Code

public function getReferencedUuids($text) {
  $result = [];
  $dom = Html::load($text);
  $xpath = new \DOMXPath($dom);
  if (strpos($text, 'data-entity-uuid') !== FALSE) {
    foreach ($xpath
      ->query('//drupal-entity[@data-entity-type and @data-entity-uuid]') as $node) {

      /** @var \DOMElement $node */
      $uuid = NULL;
      if ($uuid = $node
        ->getAttribute('data-entity-uuid')) {
        $result[] = $uuid;
      }
    }
  }
  return $result;
}