Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
informea_api
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
informea_api
Commits
d1df8751
Commit
d1df8751
authored
10 months ago
by
Stefan Butura
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3416538
by rodrigoaguilera: Add suport for contact roles with static/fixed treaty
parent
ae7baa5d
Branches
Branches containing commit
Tags
8.x-1.0
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/Plugin/Field/FieldFormatter/RoleWithTreatyEntityReferenceFormatter.php
+94
-0
94 additions, 0 deletions
...FieldFormatter/RoleWithTreatyEntityReferenceFormatter.php
with
94 additions
and
0 deletions
src/Plugin/Field/FieldFormatter/RoleWithTreatyEntityReferenceFormatter.php
0 → 100644
+
94
−
0
View file @
d1df8751
<?php
namespace
Drupal\informea_api\Plugin\Field\FieldFormatter
;
use
Drupal\Core\Field\FieldItemListInterface
;
use
Drupal\Core\Field\Plugin\Field\FieldFormatter\EntityReferenceLabelFormatter
;
use
Drupal\Core\Form\FormStateInterface
;
/**
* Plugin implementation of the 'Role with treaty' formatter.
*
* @FieldFormatter(
* id = "informea_api_role_with_treaty",
* label = @Translation("[InforMEA] Role with treaty"),
* field_types = {
* "entity_reference",
* }
* )
*/
class
RoleWithTreatyEntityReferenceFormatter
extends
EntityReferenceLabelFormatter
{
use
SerializerObjectTrait
;
/**
* {@inheritdoc}
*/
public
static
function
defaultSettings
()
:
array
{
$settings
=
[
'treaties'
=>
''
,
]
+
parent
::
defaultSettings
();
$settings
[
'link'
]
=
FALSE
;
return
$settings
;
}
/**
* {@inheritdoc}
*/
public
function
settingsForm
(
array
$form
,
FormStateInterface
$form_state
)
:
array
{
$form
[
'treaties'
]
=
[
'#type'
=>
'textfield'
,
'#title'
=>
$this
->
t
(
'Treaty'
),
'#description'
=>
$this
->
t
(
'Treaty machine name.'
),
'#default_value'
=>
$this
->
getSetting
(
'treaties'
),
'#required'
=>
TRUE
,
];
return
$form
;
}
/**
* {@inheritdoc}
*/
public
function
settingsSummary
()
:
array
{
$summary
=
[];
$summary
[]
=
$this
->
t
(
'Treaties: @treaties'
,
[
'@treaties'
=>
$this
->
getSetting
(
'treaties'
)]);
return
$summary
;
}
/**
* {@inheritdoc}
*/
public
function
viewElements
(
FieldItemListInterface
$items
,
$langcode
)
:
array
{
$roles
=
[];
$elements
=
parent
::
viewElements
(
$items
,
$langcode
);
$treaties
=
$this
->
getTreaties
(
$items
);
foreach
(
$elements
as
$element
)
{
$roles
[]
=
[
'treaty'
=>
reset
(
$treaties
),
'role'
=>
$element
[
'#plain_text'
],
];
}
return
$this
->
serialize
(
$roles
);
}
/**
* Get the treaties.
*
* @return array
* The treaties.
*/
protected
function
getTreaties
(
FieldItemListInterface
$items
)
:
array
{
$treaties
=
$this
->
getSetting
(
'treaties'
);
$treaties
=
explode
(
','
,
$treaties
);
foreach
(
$treaties
as
&
$treaty
)
{
$treaty
=
trim
(
$treaty
);
}
return
$treaties
;
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment