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
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\linkchecker\Plugin\LinkStatusHandlerBase implements ContainerFactoryPluginInterface, LinkStatusHandlerInterface
- class \Drupal\linkchecker\Plugin\LinkStatusHandler\Unpublish404
- class \Drupal\linkchecker\Plugin\LinkStatusHandlerBase implements ContainerFactoryPluginInterface, LinkStatusHandlerInterface
Expanded class hierarchy of Unpublish404
File
- src/
Plugin/ LinkStatusHandler/ Unpublish404.php, line 22
Namespace
Drupal\linkchecker\Plugin\LinkStatusHandlerView 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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
LinkStatusHandlerBase:: |
protected | property | The account switcher. | |
LinkStatusHandlerBase:: |
protected | property | The entity type manager. | |
LinkStatusHandlerBase:: |
protected | property | Number of items per batch. | |
LinkStatusHandlerBase:: |
protected | property | The Linkchecker settings. | |
LinkStatusHandlerBase:: |
protected | property | The queue. | |
LinkStatusHandlerBase:: |
public static | function |
Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface:: |
1 |
LinkStatusHandlerBase:: |
public | function |
Handles a status code of link. Overrides LinkStatusHandlerInterface:: |
|
LinkStatusHandlerBase:: |
public | function |
Creates a queue for handling. Overrides LinkStatusHandlerInterface:: |
|
LinkStatusHandlerBase:: |
protected | function | Helper function to switch session. | |
LinkStatusHandlerBase:: |
protected | function | Helper function to switch session back. | |
LinkStatusHandlerBase:: |
public | function |
LinkStatusHandlerBase constructor. Overrides PluginBase:: |
1 |
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
Unpublish404:: |
protected | function |
Handles a status code of link. Overrides LinkStatusHandlerBase:: |
|
Unpublish404:: |
protected | function |
Gets list of items to queue. Overrides LinkStatusHandlerBase:: |