You are here

class LinkStatusHandle in Link checker 8

Handler a status of a link.

Plugin annotation


@QueueWorker(
  id = "linkchecker_status_handle",
  title = @Translation("LinkChecker status handle"),
  cron = {"time" = 60}
)

Hierarchy

Expanded class hierarchy of LinkStatusHandle

File

src/Plugin/QueueWorker/LinkStatusHandle.php, line 21

Namespace

Drupal\linkchecker\Plugin\QueueWorker
View source
class LinkStatusHandle extends QueueWorkerBase implements ContainerFactoryPluginInterface {

  /**
   * The entity type manager.
   *
   * @var \Drupal\Core\Entity\EntityTypeManagerInterface
   */
  protected $entityTypeManager;

  /**
   * The status handler manager.
   *
   * @var \Drupal\linkchecker\Plugin\LinkStatusHandlerManager
   */
  protected $statusHandlerManager;

  /**
   * LinkExtract constructor.
   */
  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;
  }

  /**
   * {@inheritdoc}
   */
  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'));
  }

  /**
   * {@inheritdoc}
   */
  public function processItem($data) {
    $response = $data['response'];
    try {

      /** @var \Drupal\linkchecker\Plugin\LinkStatusHandlerInterface $handler */
      $handler = $this->statusHandlerManager
        ->createInstance($data['handler']);
    } catch (PluginNotFoundException $e) {

      // Skip it.
    }
    foreach ($data['links'] as $linkId) {
      try {

        /** @var \Drupal\linkchecker\LinkCheckerLinkInterface $link */
        $link = $this->entityTypeManager
          ->getStorage('linkcheckerlink')
          ->load($linkId);
        $handler
          ->handle($link, $response);
      } catch (\Exception $e) {

        // If we can`t load Link or entity - just skip it.
      }
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
LinkStatusHandle::$entityTypeManager protected property The entity type manager.
LinkStatusHandle::$statusHandlerManager protected property The status handler manager.
LinkStatusHandle::create public static function Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface::create
LinkStatusHandle::processItem public function Works on a single queue item. Overrides QueueWorkerInterface::processItem
LinkStatusHandle::__construct public function LinkExtract constructor. Overrides PluginBase::__construct
PluginBase::$configuration protected property Configuration information passed into the plugin. 1
PluginBase::$pluginDefinition protected property The plugin implementation definition. 1
PluginBase::$pluginId protected property The plugin_id.
PluginBase::DERIVATIVE_SEPARATOR constant A string which is used to separate base plugin IDs from the derivative ID.
PluginBase::getBaseId public function Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface::getBaseId
PluginBase::getDerivativeId public function Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface::getDerivativeId
PluginBase::getPluginDefinition public function Gets the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition 3
PluginBase::getPluginId public function Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface::getPluginId
PluginBase::isConfigurable public function Determines if the plugin is configurable.