public function EntityEmbed::parseEntitiesFromText in Entity Usage 8
Same name and namespace in other branches
- 8.2 src/Plugin/EntityUsage/Track/EntityEmbed.php \Drupal\entity_usage\Plugin\EntityUsage\Track\EntityEmbed::parseEntitiesFromText()
- 8.3 src/Plugin/EntityUsage/Track/EntityEmbed.php \Drupal\entity_usage\Plugin\EntityUsage\Track\EntityEmbed::parseEntitiesFromText()
Parse an HTML snippet looking for embedded entities.
Parameters
string $text: The partial (X)HTML snippet to load. Invalid markup will be corrected on import.
Return value
array An array of all embedded entities found, where keys are the uuids and the values are the entity types.
Overrides EmbedTrackInterface::parseEntitiesFromText
File
- src/
Plugin/ EntityUsage/ Track/ EntityEmbed.php, line 21
Class
- EntityEmbed
- Tracks usage of entities related in entity_reference fields.
Namespace
Drupal\entity_usage\Plugin\EntityUsage\TrackCode
public function parseEntitiesFromText($text) {
$dom = Html::load($text);
$xpath = new \DOMXPath($dom);
$entities = [];
foreach ($xpath
->query('//drupal-entity[@data-entity-type and @data-entity-uuid]') as $node) {
// Note that this does not cover 100% of the situations. In the (unlikely
// but possible) use case where the user embeds the same entity twice in
// the same field, we are just recording 1 usage for this target entity,
// when we should record 2. The alternative is to add a lot of complexity
// to the update logic of our plugin, to deal with all possible
// combinations in the update scenario.
// @TODO Re-evaluate if this is worth the effort and overhead.
$entities[$node
->getAttribute('data-entity-uuid')] = $node
->getAttribute('data-entity-type');
}
return $entities;
}