Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
redirect_metrics
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
redirect_metrics
Merge requests
!7
Use OOP hooks
Code
Review changes
Check out branch
Download
Patches
Plain diff
Open
Use OOP hooks
issue/redirect_metrics-3497621:3497621-oop-hooks
into
2.x
Overview
0
Commits
2
Pipelines
2
Changes
4
Open
Mohit Aghera
requested to merge
issue/redirect_metrics-3497621:3497621-oop-hooks
into
2.x
5 months ago
Overview
0
Commits
2
Pipelines
2
Changes
4
Expand
Closes
#3497621
0
0
Merge request reports
Compare
2.x
version 1
86a74e63
5 months ago
2.x (HEAD)
and
latest version
latest version
9f4b51b8
2 commits,
5 months ago
version 1
86a74e63
1 commit,
5 months ago
4 files
+
54
−
14
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
4
Search (e.g. *.vue) (Ctrl+P)
src/Hook/RedirectMetricsHooks.php
0 → 100644
+
42
−
0
Options
<?php
declare
(
strict_types
=
1
);
namespace
Drupal\redirect_metrics\Hook
;
use
Drupal\Core\Entity\EntityTypeInterface
;
use
Drupal\Core\Hook\Attribute\Hook
;
use
Drupal\redirect\Entity\Redirect
;
use
Drupal\redirect_metrics
\RedirectMetricsFieldDefinitions
;
/**
* Hook implementations for the redirect_metrics module.
*/
class
RedirectMetricsHooks
{
/**
* Implements hook_entity_base_field_info().
*/
#[Hook('entity_base_field_info')]
public
function
entityBaseFieldInfo
(
EntityTypeInterface
$entityType
):
array
{
if
(
$entityType
->
id
()
!==
'redirect'
)
{
return
[];
}
return
RedirectMetricsFieldDefinitions
::
getAll
();
}
/**
* Implements hook_ENTITY_TYPE_presave().
*/
#[Hook('redirect_presave')]
public
function
redirectPresave
(
Redirect
$redirect
):
void
{
// Initialise the default metrics when a new redirect is created.
if
(
$redirect
->
isNew
())
{
// Set the access count if it's empty.
if
(
$redirect
->
access_count
->
isEmpty
())
{
$redirect
->
access_count
->
value
=
0
;
}
}
}
}
Loading