Missing schema entry for type file_link link_to_entity when used in a view

Created on 4 January 2017, over 8 years ago
Updated 26 June 2025, 8 days ago

Create a content type with file field.
Create a view and link the title to the file and not the content type.
Exported view .yml file contains

        title:
          id: title
          table: node_field_data
          field: title
          type: file_link
          settings:
            link_to_entity: false

Run the config inspector and it reported an error.
I did not expect it to report an error.

This prevents other profile tests from running, if the content type is part of a module which is required by the installed profile.

🐛 Bug report
Status

Needs work

Version

11.0 🔥

Component

file system

Created by

🇬🇧United Kingdom somersoft

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

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.

  • 🇮🇳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 in getInstance() 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)
    Because BaseFieldFileFormatterBase 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.

Production build 0.71.5 2024