Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
V
votingapi_widgets
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
votingapi_widgets
Merge requests
!23
Resolve
#3502021
"Support for object"
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Resolve
#3502021
"Support for object"
issue/votingapi_widgets-3502021:3502021-support-for-object
into
2.0.x
Overview
0
Commits
5
Pipelines
6
Changes
5
Merged
Tim Rohaly
requested to merge
issue/votingapi_widgets-3502021:3502021-support-for-object
into
2.0.x
2 months ago
Overview
0
Commits
5
Pipelines
6
Changes
5
Expand
Closes
#3502021
0
0
Merge request reports
Compare
2.0.x
version 5
f7f3ec8a
2 months ago
version 4
2a668590
2 months ago
version 3
b00f3d5e
2 months ago
version 2
07cca8d2
2 months ago
version 1
6b0418b1
2 months ago
2.0.x (base)
and
latest version
latest version
f7f3ec8a
5 commits,
2 months ago
version 5
f7f3ec8a
5 commits,
2 months ago
version 4
2a668590
4 commits,
2 months ago
version 3
b00f3d5e
4 commits,
2 months ago
version 2
07cca8d2
3 commits,
2 months ago
version 1
6b0418b1
2 commits,
2 months ago
5 files
+
186
−
44
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
5
Search (e.g. *.vue) (Ctrl+P)
src/Hook/VotingApiWidgetsEntityHooks.php
0 → 100644
+
63
−
0
Options
<?php
declare
(
strict_types
=
1
);
namespace
Drupal\votingapi_widgets\Hook
;
use
Drupal\Core\Entity\EntityTypeInterface
;
use
Drupal\Core\Field\BaseFieldDefinition
;
use
Drupal\Core\Hook\Attribute\Hook
;
use
Drupal\Core\StringTranslation\TranslatableMarkup
;
use
Drupal\field\Entity\FieldStorageConfig
;
use
Drupal\votingapi_widgets
\Plugin\VotingApiWidgetManager
;
/**
* Hook implementations used to create and dispatch Entity Events.
*/
final
class
VotingApiWidgetsEntityHooks
{
/**
* Constructs a new VotingApiWidgetsEntityHooks service.
*
* @param \Drupal\votingapi_widgets\Plugin\VotingApiWidgetManager $widgetManager
* The entity_type.manager service.
*/
public
function
__construct
(
protected
VotingApiWidgetManager
$widgetManager
,
)
{}
/**
* Implements hook_entity_base_field_info().
*/
#[Hook('entity_base_field_info')]
public
function
entityBaseFieldInfo
(
EntityTypeInterface
$entity_type
):
array
{
$fields
=
[];
// Add the field_name as a base field.
if
(
$entity_type
->
id
()
!=
'vote'
)
{
return
$fields
;
}
$fields
[
'field_name'
]
=
BaseFieldDefinition
::
create
(
'string'
)
->
setLabel
(
new
TranslatableMarkup
(
'Field name'
))
->
setName
(
'field_name'
)
->
setRevisionable
(
FALSE
)
->
setRequired
(
FALSE
)
->
setDescription
(
new
TranslatableMarkup
(
'Holds the field name.'
))
->
setPropertyConstraints
(
'value'
,
[
'Length'
=>
[
'max'
=>
FieldStorageConfig
::
NAME_MAX_LENGTH
]]);
return
$fields
;
}
/**
* Implements hook_entity_type_build().
*/
#[Hook('entity_type_build')]
public
function
entityTypeBuild
(
array
&
$entity_types
):
void
{
$plugins
=
$this
->
widgetManager
->
getDefinitions
();
foreach
(
$plugins
as
$plugin_id
=>
$definition
)
{
$entity_types
[
'vote'
]
->
setFormClass
(
'votingapi_'
.
$plugin_id
,
'Drupal\votingapi_widgets\Form\BaseRatingForm'
);
}
}
}
Loading