$formatter_plugin_manager = \Drupal::
service('plugin.manager.field.formatter'
);
$field_test_default_settings =
$formatter_plugin_manager->
getDefaultSettings('field_test_default'
);
$field_test_with_prepare_view_settings =
$formatter_plugin_manager->
getDefaultSettings('field_test_with_prepare_view'
);
$output =
[ 'field_test_default' =>
$field_test_default_settings['test_formatter_setting'
] . '|' .
$value,
'field_test_with_prepare_view' =>
$field_test_with_prepare_view_settings['test_formatter_setting_additional'
] . '|' .
$value . '|' .
($value + 1
),
];
// Check that the field is displayed with the default formatter in 'rss'
// mode (uses 'default'), and hidden in 'teaser' mode (uses custom settings).
$this->
assertNodeViewText($node, 'rss',
$output['field_test_default'
], "The field is displayed as expected in view modes that use 'default' settings."
);
$this->
assertNodeViewNoText($node, 'teaser',
$value, "The field is hidden in view modes that use custom settings."
);
// Change formatter for 'default' mode, check that the field is displayed
// accordingly in 'rss' mode.
$edit =
[ 'fields[field_test][type]' => 'field_test_with_prepare_view',
'fields[field_test][region]' => 'content',
];
$this->
drupalGet('admin/structure/types/manage/' .
$this->type . '/display'
);
$this->
submitForm($edit, 'Save'
);
$this->
assertNodeViewText($node, 'rss',
$output['field_test_with_prepare_view'
], "The field is displayed as expected in view modes that use 'default' settings."
);