Commit cba80407 authored by jhodgdon's avatar jhodgdon

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

parent 8e9c6950
......@@ -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.');
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment