You are here

class Unpublish404 in Link checker 8

Unpublish entities on 404 link response.

Plugin annotation


@LinkStatusHandler(
  id = "unpublish_404",
  label = @Translation("Unpublish on 404"),
  status_codes = {
    404,
  }
)

Hierarchy

Expanded class hierarchy of Unpublish404

File

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

Namespace

Drupal\linkchecker\Plugin\LinkStatusHandler
View source
class Unpublish404 extends LinkStatusHandlerBase {

  /**
   * {@inheritdoc}
   */
  protected function getItems(LinkCheckerLinkInterface $link, ResponseInterface $response) {

    // If unpublishing limit is reached,
    // unpublish all entities having this link.
    $actionStatusCode404 = $this->linkcheckerSetting
      ->get('error.action_status_code_404');
    if ($actionStatusCode404 && $actionStatusCode404 <= $link
      ->getFailCount()) {
      return parent::getItems($link, $response);
    }
    else {
      return [];
    }
  }

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

}

Members

Namesort descending Modifiers Type Description Overrides
LinkStatusHandlerBase::$accountSwitcher protected property The account switcher.
LinkStatusHandlerBase::$entityTypeManager protected property The entity type manager.
LinkStatusHandlerBase::$itemsPerBatch protected property Number of items per batch.
LinkStatusHandlerBase::$linkcheckerSetting protected property The Linkchecker settings.
LinkStatusHandlerBase::$queue protected property The queue.
LinkStatusHandlerBase::create public static function Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface::create 1
LinkStatusHandlerBase::handle public function Handles a status code of link. Overrides LinkStatusHandlerInterface::handle
LinkStatusHandlerBase::queueItems public function Creates a queue for handling. Overrides LinkStatusHandlerInterface::queueItems
LinkStatusHandlerBase::switchSession protected function Helper function to switch session.
LinkStatusHandlerBase::switchSessionBack protected function Helper function to switch session back.
LinkStatusHandlerBase::__construct public function LinkStatusHandlerBase constructor. Overrides PluginBase::__construct 1
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.
Unpublish404::doHandle protected function Handles a status code of link. Overrides LinkStatusHandlerBase::doHandle
Unpublish404::getItems protected function Gets list of items to queue. Overrides LinkStatusHandlerBase::getItems