Field linker provides incomplete fieldDefinition which leads to wrong setting options

Created on 8 April 2020, about 4 years ago
Updated 29 November 2023, 7 months ago

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!

πŸ› Bug report
Status

Active

Version

3.0

Component

field_link Formatter

Created by

πŸ‡©πŸ‡ͺGermany Anybody Porta Westfalica

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡©πŸ‡ͺGermany Anybody Porta Westfalica

    Happy to review MR if anyone finds the reason and solution. We're not actively using field_linker.

  • πŸ‡ͺπŸ‡ΈSpain Carlitus

    I have the same problem, when i edit the view display, when using Field formatter with inline settings i don't see all the responsive image that i have.

    As a temporal solution i can export config, change the responsive image id and import.

Production build 0.69.0 2024