You are here

protected function Unpublish404::doHandle in Link checker 8

Handles a status code of link.

Parameters

\Drupal\linkchecker\LinkCheckerLinkInterface $link: The link.

\Psr\Http\Message\ResponseInterface $response: The response of link checking.

\Drupal\Core\Entity\FieldableEntityInterface $entity: The entity with proper translation loaded.

Overrides LinkStatusHandlerBase::doHandle

File

src/Plugin/LinkStatusHandler/Unpublish404.php, line 43

Class

Unpublish404
Unpublish entities on 404 link response.

Namespace

Drupal\linkchecker\Plugin\LinkStatusHandler

Code

protected function doHandle(LinkCheckerLinkInterface $link, ResponseInterface $response, FieldableEntityInterface $entity) {

  // If unpublishing limit is reached, unpublish entity having this link.
  $actionStatusCode404 = $this->linkcheckerSetting
    ->get('error.action_status_code_404');
  if ($actionStatusCode404 && $actionStatusCode404 <= $link
    ->getFailCount() && $link
    ->isExists()) {
    if ($entity instanceof EntityPublishedInterface && $entity
      ->isPublished()) {
      $entity
        ->setUnpublished();
      $entity
        ->save();
    }
  }
}