abstract class TextFieldEmbedBase in Entity Usage 8.4
Base class for plugins tracking usage in entities embedded in WYSIWYG fields.
Hierarchy
- class \Drupal\entity_usage\EntityUsageBase extends \Drupal\entity_track\EntityTrackBase
- class \Drupal\entity_usage\Plugin\EntityTrack\Track\TextFieldEmbedBase implements EmbedTrackInterface
Expanded class hierarchy of TextFieldEmbedBase
File
- src/
Plugin/ EntityTrack/ Track/ TextFieldEmbedBase.php, line 12
Namespace
Drupal\entity_usage\Plugin\EntityTrack\TrackView source
abstract class TextFieldEmbedBase extends EntityUsageBase implements EmbedTrackInterface {
/**
* {@inheritdoc}
*/
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) {
// Check if the target entity exists since text fields are not
// automatically updated when an entity is removed.
if ($target_entity = $this->entityRepository
->loadEntityByUuid($entity_type, $uuid)) {
$valid_entities[] = $target_entity
->getEntityTypeId() . "|" . $target_entity
->id();
}
}
return array_unique($valid_entities);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
EmbedTrackInterface:: |
public | function | Parse an HTML snippet looking for embedded entities. | 4 |
EntityUsageBase:: |
protected | property | The EntityRepository service. | |
EntityUsageBase:: |
protected | property | The usage config. | |
EntityUsageBase:: |
protected | property | The usage tracking service. | |
EntityUsageBase:: |
public static | function | 2 | |
EntityUsageBase:: |
public | function | ||
EntityUsageBase:: |
public | function | ||
EntityUsageBase:: |
public | function | ||
EntityUsageBase:: |
public | function | Plugin constructor. | 2 |
TextFieldEmbedBase:: |
public | function |
Retrieve the target entity(ies) from a field item value. Overrides EntityUsageBase:: |