- 🇮🇳India mohit_aghera Rajkot
I've visited this issue as part of bug-smash triage. Sharing the finding.
The following config seems invalid to me.
title: id: title table: node_field_data field: title type: file_link settings: link_to_entity: false
Reason is, field formatter `file_link` doesn't have any setting called `link_to_entity`.
https://git.drupalcode.org/project/drupal/-/blob/11.x/core/modules/file/...
Even it's base class doesn't have `link_to_entity` either.To debug further why this option appears, I checked
FormatterPluginManager
class.
This class instantiates the formatter.
So when we are adding `file_link` formatter on title, the control comes ingetInstance()
method of the class.
https://git.drupalcode.org/project/drupal/-/blob/11.x/core/lib/Drupal/Co...In the
getInstance()
method, incoming argument array `$options` is correct and it contains the `file_link` formatter.
i.e.$options['configuration']['type']
value is `file_link`.Now in the following snippet is swapping `file_link` formatter with the string formatter.
if (!isset($definition['class']) || !in_array($field_type, $definition['field_types']) || !$definition['class']::isApplicable($field_definition)) { // Grab the default widget for the field type. $field_type_definition = $this->fieldTypeManager->getDefinition($field_type); if (empty($field_type_definition['default_formatter'])) { return FALSE; } $plugin_id = $field_type_definition['default_formatter']; }
The following condition is failing.
$definition['class']::isApplicable($field_definition)
BecauseBaseFieldFileFormatterBase
class'isApplicable()
fails since $field_definition for title field doesn't have target file type.
Since that fails, we are swapping the formatter with string formatter and it displays the `link_to_entity` form and it has configuration.Possibly one solution can be to restrict the options in field formatter options when we configure the field in views.
https://git.drupalcode.org/project/drupal/-/blob/11.x/core/modules/views...We can filter options in `buildOptionsForm()`
public function buildOptionsForm(&$form, FormStateInterface $form_state) { parent::buildOptionsForm($form, $form_state); $field = $this->getFieldDefinition(); $formatters = $this->formatterPluginManager->getOptions($field->getType()); foreach ($formatters as $id => $formatter) { $definition = $this->formatterPluginManager->getDefinition($id); if (!$definition['class']::isApplicable($field)) { unset($formatters[$id]); } }
I'm not quite sure if this is the right approach.