Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
akismet
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
akismet
Merge requests
!18
Create akismet.views.inc
Code
Review changes
Check out branch
Download
Patches
Plain diff
Open
Create akismet.views.inc
issue/akismet-3160714:3160714-views-integration
into
2.x
Overview
0
Commits
3
Pipelines
0
Changes
1
Open
Arlina Espinoza Rhoton
requested to merge
issue/akismet-3160714:3160714-views-integration
into
2.x
2 years ago
Overview
0
Commits
3
Pipelines
0
Changes
1
Expand
Closes
#3160714
0
0
Merge request reports
Compare
2.x
version 2
1cf2146f
2 years ago
version 1
e3422205
2 years ago
2.x (HEAD)
and
latest version
latest version
333866ec
3 commits,
2 years ago
version 2
1cf2146f
2 commits,
2 years ago
version 1
e3422205
1 commit,
2 years ago
1 file
+
200
−
0
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
akismet.views.inc
0 → 100644
+
200
−
0
Options
<?php
/**
* @file
* Provide views data for akismet module.
*
* @ingroup views_module_handlers
*/
/**
* Implements hook_views_data().
*/
function
akismet_views_data
()
{
$data
[
'akismet'
][
'table'
][
'group'
]
=
t
(
'Akismet'
);
$data
[
'akismet'
][
'table'
][
'base'
]
=
[
'title'
=>
t
(
'Akismet'
),
'help'
=>
t
(
'Stores Akismet responses for content.'
),
];
$data
[
'akismet'
][
'entity'
]
=
[
'title'
=>
t
(
'Entity type'
),
'help'
=>
t
(
'Entity type of the content.'
),
'field'
=>
[
'id'
=>
'standard'
,
],
'filter'
=>
[
'id'
=>
'string'
,
],
'sort'
=>
[
'id'
=>
'standard'
,
],
'argument'
=>
[
'id'
=>
'string'
,
],
];
$data
[
'akismet'
][
'id'
]
=
[
'title'
=>
t
(
'ID'
),
'help'
=>
t
(
'Unique entity ID of the content.'
),
'field'
=>
[
'id'
=>
'numeric'
,
],
'filter'
=>
[
'id'
=>
'numeric'
,
],
'sort'
=>
[
'id'
=>
'numeric'
,
],
'argument'
=>
[
'id'
=>
'standard'
,
],
];
$data
[
'akismet'
][
'form_id'
]
=
[
'title'
=>
t
(
'Form ID'
),
'help'
=>
t
(
'The form_id of the form being protected.'
),
'field'
=>
[
'id'
=>
'standard'
,
],
'filter'
=>
[
'id'
=>
'string'
,
],
'sort'
=>
[
'id'
=>
'standard'
,
],
'argument'
=>
[
'id'
=>
'string'
,
],
];
$data
[
'akismet'
][
'guid'
]
=
[
'title'
=>
t
(
'GUID'
),
'help'
=>
t
(
'The GUID returned by Akismet.'
),
'field'
=>
[
'id'
=>
'standard'
,
],
'filter'
=>
[
'id'
=>
'string'
,
],
'sort'
=>
[
'id'
=>
'standard'
,
],
'argument'
=>
[
'id'
=>
'string'
,
],
];
$data
[
'akismet'
][
'changed'
]
=
[
'title'
=>
t
(
'Changed'
),
'help'
=>
t
(
'Timestamp when the data was changed.'
),
'field'
=>
[
'id'
=>
'date'
,
],
'filter'
=>
[
'id'
=>
'date'
,
],
'sort'
=>
[
'id'
=>
'date'
,
],
];
$data
[
'akismet'
][
'moderate'
]
=
[
'title'
=>
t
(
'Needs Moderation'
),
'help'
=>
t
(
'Whether the content needs to be moderated.'
),
'field'
=>
[
'id'
=>
'boolean'
,
],
'filter'
=>
[
'id'
=>
'boolean'
,
'label'
=>
t
(
'Needs Moderation'
),
'type'
=>
'yes-no'
,
'accept null'
=>
TRUE
,
'use_equal'
=>
TRUE
,
],
'sort'
=>
[
'id'
=>
'standard'
,
],
];
$data
[
'akismet'
][
'classification'
]
=
[
'title'
=>
t
(
'Classification'
),
'help'
=>
t
(
'Result of text analysis: "ham", "spam" or "unsure".'
),
'field'
=>
[
'id'
=>
'standard'
,
],
'filter'
=>
[
'id'
=>
'string'
,
],
'sort'
=>
[
'id'
=>
'standard'
,
],
'argument'
=>
[
'id'
=>
'string'
,
],
];
return
$data
;
}
/**
* Implements hook_views_data_alter().
*/
function
akismet_views_data_alter
(
array
&
$data
)
{
$entityTypeManager
=
\Drupal
::
entityTypeManager
();
// Provide integration with node and comment node types.
$entityTypeIds
=
[
'node'
,
'comment'
,
];
foreach
(
$entityTypeIds
as
$entityTypeId
)
{
$entityType
=
$entityTypeManager
->
getDefinition
(
$entityTypeId
,
FALSE
);
if
(
$entityType
&&
$entityType
->
hasHandlerClass
(
'views_data'
))
{
$base_table
=
$entityTypeManager
->
getHandler
(
$entityTypeId
,
'views_data'
)
->
getViewsTableForEntityType
(
$entityType
);
// Entity relationship to akismet data.
$data
[
$base_table
][
'akismet_relationship'
]
=
[
'title'
=>
t
(
'@entity_label Akismet data'
,
[
'@entity_label'
=>
$entityType
->
getLabel
()]),
'help'
=>
t
(
'Link results to Akismet spam prevention data.'
),
'relationship'
=>
[
'group'
=>
t
(
'Akismet'
),
'label'
=>
t
(
'Akismet'
),
'base'
=>
'akismet'
,
'base field'
=>
'id'
,
'field'
=>
$entityType
->
getKey
(
'id'
),
'relationship field'
=>
$entityType
->
getKey
(
'id'
),
'id'
=>
'standard'
,
'extra'
=>
[
[
'field'
=>
'entity'
,
'value'
=>
$entityTypeId
,
],
],
],
];
// Akismet table relationship to the entity.
$data
[
'akismet'
][
$entityTypeId
.
'_relationship'
]
=
[
'title'
=>
t
(
'Related @entity_label entity'
,
[
'@entity_label'
=>
$entityType
->
getLabel
()]),
'help'
=>
t
(
'Link to related @entity_label.'
,
[
'@entity_label'
=>
$entityType
->
getLabel
()]),
'relationship'
=>
[
'group'
=>
$entityType
->
getLabel
(),
'label'
=>
$entityType
->
getLabel
(),
'base'
=>
$base_table
,
'base field'
=>
$entityType
->
getKey
(
'id'
),
'field'
=>
'id'
,
'id'
=>
'standard'
,
'extra'
=>
[
[
'left_field'
=>
'entity'
,
'value'
=>
$entityTypeId
,
],
],
],
];
}
}
}
Loading