You are here

protected function Repair301::getItems in Link checker 8

Gets list of items to queue.

List should be like: [ [ 'entity_type' => 'node', 'entity_id' => 123, 'link_id' => 12 ], ... [ 'entity_type' => 'paragraph', 'entity_id' => 1234, 'link_id' => 123 ], ]

Parameters

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

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

Return value

array Array of items.

Overrides LinkStatusHandlerBase::getItems

File

src/Plugin/LinkStatusHandler/Repair301.php, line 65

Class

Repair301
Repairs 301 links.

Namespace

Drupal\linkchecker\Plugin\LinkStatusHandler

Code

protected function getItems(LinkCheckerLinkInterface $link, ResponseInterface $response) {

  // A HTTP status code of 301 tells us an existing link have changed to
  // a new link. The remote site owner was so kind to provide us the new
  // link and if we trust this change we are able to replace the old link
  // with the new one without any hand work.
  $autoRepair301 = $this->linkcheckerSetting
    ->get('error.action_status_code_301');
  $redirectUrl = $response
    ->getHeaderLine('Location');
  if ($autoRepair301 && $autoRepair301 <= $link
    ->getFailCount() && UrlHelper::isValid($redirectUrl, TRUE)) {
    return parent::getItems($link, $response);
  }
  else {
    return [];
  }
}