You are here

protected function EditorDetectorBase::extractEntitiesFromText in Lingotek Translation 4.0.x

Same name and namespace in other branches
  1. 3.6.x src/Plugin/RelatedEntitiesDetector/EditorDetectorBase.php \Drupal\lingotek\Plugin\RelatedEntitiesDetector\EditorDetectorBase::extractEntitiesFromText()
  2. 3.7.x src/Plugin/RelatedEntitiesDetector/EditorDetectorBase.php \Drupal\lingotek\Plugin\RelatedEntitiesDetector\EditorDetectorBase::extractEntitiesFromText()
  3. 3.8.x src/Plugin/RelatedEntitiesDetector/EditorDetectorBase.php \Drupal\lingotek\Plugin\RelatedEntitiesDetector\EditorDetectorBase::extractEntitiesFromText()

Extract entities referenced by a given text.

Parameters

string $text: The text to extract the entities from.

Return value

array Array of entities in the form of (uuid => entity_type_id).

1 call to EditorDetectorBase::extractEntitiesFromText()
EditorDetectorBase::extract in src/Plugin/RelatedEntitiesDetector/EditorDetectorBase.php
Extract nested and related content.
1 method overrides EditorDetectorBase::extractEntitiesFromText()
HtmlLinkDetector::extractEntitiesFromText in src/Plugin/RelatedEntitiesDetector/HtmlLinkDetector.php
Extract entities referenced by a given text.

File

src/Plugin/RelatedEntitiesDetector/EditorDetectorBase.php, line 130

Class

EditorDetectorBase

Namespace

Drupal\lingotek\Plugin\RelatedEntitiesDetector

Code

protected function extractEntitiesFromText($text) {
  $dom = Html::load($text);
  $xpath = new \DOMXPath($dom);
  $entities = [];
  foreach ($xpath
    ->query($this->xpath) as $node) {
    $entities[$node
      ->getAttribute('data-entity-uuid')] = $node
      ->getAttribute('data-entity-type');
  }
  return $entities;
}