public function BrokenLink::merge in Broken Link 8
Same name and namespace in other branches
- 8.3 src/Entity/BrokenLink.php \Drupal\broken_link\Entity\BrokenLink::merge()
- 8.2 src/Entity/BrokenLink.php \Drupal\broken_link\Entity\BrokenLink::merge()
Method to create or update broken link and its hits.
Parameters
string $request_path: Broken link.
File
- src/
Entity/ BrokenLink.php, line 95
Class
- BrokenLink
- Defines the broken link entity class.
Namespace
Drupal\broken_link\EntityCode
public function merge($request_path) {
$broken_link = $this
->loadByLink($request_path);
if ($broken_link === NULL) {
$broken_link = $this
->create();
$broken_link->link = $request_path;
$broken_link->hits = 1;
}
else {
$hits = (int) $broken_link
->get('hits')
->get(0)
->getValue()['value'];
$broken_link->hits = ++$hits;
}
$broken_link
->save();
}