Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
drupal
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
drupal
Commits
cba80407
Commit
cba80407
authored
11 years ago
by
Jennifer Hodgdon
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#2029581
by andrewmacpherson, swentel: Better examples for field formatter alter hooks
parent
8e9c6950
Branches
Branches containing commit
Tags
Tags containing commit
2 merge requests
!7452
Issue #1797438. HTML5 validation is preventing form submit and not fully...
,
!789
Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
core/modules/field_ui/field_ui.api.php
+5
-4
5 additions, 4 deletions
core/modules/field_ui/field_ui.api.php
with
5 additions
and
4 deletions
core/modules/field_ui/field_ui.api.php
+
5
−
4
View file @
cba80407
...
...
@@ -28,8 +28,9 @@
* @see \Drupal\field_ui\DisplayOverView.
*/
function
hook_field_formatter_settings_form_alter
(
&
$element
,
&
$form_state
,
$context
)
{
// Add a 'mysetting' checkbox to the settings form for 'foo_field' fields.
if
(
$context
[
'field'
][
'type'
]
==
'foo_field'
)
{
// Add a 'mysetting' checkbox to the settings form for 'foo_formatter'
// field formatters.
if
(
$context
[
'formatter'
]
->
getPluginId
()
==
'foo_formatter'
)
{
$element
[
'mysetting'
]
=
array
(
'#type'
=>
'checkbox'
,
'#title'
=>
t
(
'My setting'
),
...
...
@@ -81,9 +82,9 @@ function hook_field_widget_settings_form_alter(&$element, &$form_state, $context
* @see \Drupal\field_ui\DisplayOverView.
*/
function
hook_field_formatter_settings_summary_alter
(
&
$summary
,
$context
)
{
// Append a message to the summary when an instance of foo_f
ield
has
// Append a message to the summary when an instance of foo_f
ormatter
has
// mysetting set to TRUE for the current view mode.
if
(
$context
[
'f
ield'
][
'type'
]
==
'foo_f
ield
'
)
{
if
(
$context
[
'f
ormatter'
]
->
getPluginId
()
==
'foo_f
ormatter
'
)
{
if
(
$context
[
'formatter'
]
->
getSetting
(
'mysetting'
))
{
$summary
[]
=
t
(
'My setting enabled.'
);
}
...
...
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