You are here

public function LinkExtractorService::saveLink in Link checker 8

Helper function to save link.

Saves link if it not a duplicate.

@todo should we move this method to entity storage?

Parameters

\Drupal\linkchecker\LinkCheckerLinkInterface $link: Link to save.

1 call to LinkExtractorService::saveLink()
LinkExtractorService::saveLinkMultiple in src/LinkExtractorService.php
Helper function to save links.

File

src/LinkExtractorService.php, line 347

Class

LinkExtractorService
Class LinkExtractor.

Namespace

Drupal\linkchecker

Code

public function saveLink(LinkCheckerLinkInterface $link) {
  $storage = $this->entityTypeManager
    ->getStorage($link
    ->getEntityTypeId());
  $query = $storage
    ->getQuery();
  $query
    ->condition('urlhash', LinkCheckerLink::generateHash($link
    ->getUrl()))
    ->condition('entity_id.target_id', $link
    ->getParentEntity()
    ->id())
    ->condition('entity_id.target_type', $link
    ->getParentEntity()
    ->getEntityTypeId())
    ->condition('entity_field', $link
    ->getParentEntityFieldName())
    ->condition('entity_langcode', $link
    ->getParentEntityLangcode());
  $ids = $query
    ->execute();
  if (empty($ids)) {
    $link
      ->save();
  }
}