Skip to content
Snippets Groups Projects
Commit cba80407 authored by Jennifer Hodgdon's avatar Jennifer Hodgdon
Browse files

Issue #2029581 by andrewmacpherson, swentel: Better examples for field formatter alter hooks

parent 8e9c6950
Branches
Tags
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
......@@ -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_field has
// Append a message to the summary when an instance of foo_formatter has
// mysetting set to TRUE for the current view mode.
if ($context['field']['type'] == 'foo_field') {
if ($context['formatter']->getPluginId() == 'foo_formatter') {
if ($context['formatter']->getSetting('mysetting')) {
$summary[] = t('My setting enabled.');
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment