LinkStatusHandle.php in Link checker 8
File
src/Plugin/QueueWorker/LinkStatusHandle.php
View source
<?php
namespace Drupal\linkchecker\Plugin\QueueWorker;
use Drupal\Component\Plugin\Exception\PluginNotFoundException;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Queue\QueueWorkerBase;
use Drupal\linkchecker\Plugin\LinkStatusHandlerManager;
use Symfony\Component\DependencyInjection\ContainerInterface;
class LinkStatusHandle extends QueueWorkerBase implements ContainerFactoryPluginInterface {
protected $entityTypeManager;
protected $statusHandlerManager;
public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entityTypeManager, LinkStatusHandlerManager $statusHandlerManager) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->entityTypeManager = $entityTypeManager;
$this->statusHandlerManager = $statusHandlerManager;
}
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('entity_type.manager'), $container
->get('plugin.manager.link_status_handler'));
}
public function processItem($data) {
$response = $data['response'];
try {
$handler = $this->statusHandlerManager
->createInstance($data['handler']);
} catch (PluginNotFoundException $e) {
}
foreach ($data['links'] as $linkId) {
try {
$link = $this->entityTypeManager
->getStorage('linkcheckerlink')
->load($linkId);
$handler
->handle($link, $response);
} catch (\Exception $e) {
}
}
}
}