TextFieldEmbedBase.php in Entity Usage 8.4
File
src/Plugin/EntityTrack/Track/TextFieldEmbedBase.php
View source
<?php
namespace Drupal\entity_usage\Plugin\EntityTrack\Track;
use Drupal\Core\Field\FieldItemInterface;
use Drupal\entity_usage\EmbedTrackInterface;
use Drupal\entity_usage\EntityUsageBase;
abstract class TextFieldEmbedBase extends EntityUsageBase implements EmbedTrackInterface {
public function getTargetEntities(FieldItemInterface $item) {
$item_value = $item
->getValue();
if (empty($item_value['value'])) {
return [];
}
$text = $item_value['value'];
if ($item
->getFieldDefinition()
->getType() === 'text_with_summary') {
$text .= $item_value['summary'];
}
$entities_in_text = $this
->parseEntitiesFromText($text);
$valid_entities = [];
foreach ($entities_in_text as $uuid => $entity_type) {
if ($target_entity = $this->entityRepository
->loadEntityByUuid($entity_type, $uuid)) {
$valid_entities[] = $target_entity
->getEntityTypeId() . "|" . $target_entity
->id();
}
}
return array_unique($valid_entities);
}
}
Classes
Name |
Description |
TextFieldEmbedBase |
Base class for plugins tracking usage in entities embedded in WYSIWYG fields. |