public function LinkExtractorService::extractFromEntity in Link checker 8
Extracts links from entity fields.
Parameters
\Drupal\Core\Entity\FieldableEntityInterface $entity: Entity from which to extract.
Return value
\Drupal\linkchecker\LinkCheckerLinkInterface[] Array of extracted links.
File
- src/
LinkExtractorService.php, line 92
Class
- LinkExtractorService
- Class LinkExtractor.
Namespace
Drupal\linkcheckerCode
public function extractFromEntity(FieldableEntityInterface $entity) {
$links = [];
$this->pos = 0;
foreach ($entity
->getFieldDefinitions() as $fieldDefinition) {
if ($entity instanceof TranslatableInterface && $fieldDefinition
->isTranslatable()) {
foreach ($entity
->getTranslationLanguages() as $language) {
$translation = $entity
->getTranslation($language
->getId());
$links += $this
->extractFromField($translation
->get($fieldDefinition
->getName()));
}
}
else {
$links += $this
->extractFromField($entity
->get($fieldDefinition
->getName()));
}
}
return $links;
}