Problem:
$this->fieldDefinition->getSetting('handler_settings'); doesn't seem to return the same array in field_linker wrapped field formatters as in the original field_formatter.
This should be checked here:
$fieldDefinitionHandlerSettings = $this->fieldDefinition->getSetting('handler_settings');
$target_bundles = empty($fieldDefinitionHandlerSettings['target_bundles']) ? array_keys($bundle_info->getBundleInfo($entity_type_id)) : $fieldDefinitionHandlerSettings['target_bundles'];
When using field_linker to wrap a field_formatter_from_view_display, the field_formatter_from_view_display throws the following notice:
Notice: Undefined index: target_bundles in Drupal\field_formatter\Plugin\Field\FieldFormatter\FieldFormatterBase->getAvailableFieldNames() (Zeile 149 in /var/www/vhosts/turf-times.de/d8.turf-times.de/web/modules/contrib/field_formatter/src/Plugin/Field/FieldFormatter/FieldFormatterBase.php). array(29)
Futhermore the selectable options are wrong (e.g. for a media image the fields of media video are returned). So it seems the wrapped field retrieves wrong or incomplete configuration.
Furthermore we should completely check if this part is correct:
$formatters = $this->formatterPluginManager->getOptions($field_storage_definition->getType());
$formatter_instances = array_map(
function ($formatter_id) {
// TODO: Ensure it is right to empty all values here, see:
// https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Field%21FormatterPluginManager.php/class/FormatterPluginManager/8.2.x
$configuration = [
'field_definition' => $this->fieldDefinition,
'settings' => [],
'label' => '',
'view_mode' => '',
'third_party_settings' => [],
];
return $this->formatterPluginManager->createInstance($formatter_id, $configuration);
},
array_combine(array_keys($formatters), array_keys($formatters))
);
Follow-up
As follow-up we could remove the 'link_to_entity' option again which was added in
#3032087: Add an option to link to the parent entity (field_formatter_with_inline_settings, field_formatter_from_view_display) →
and simply wrap these these other formatters!