Problem/Motivation

There is a duplication of the settings for the file_link field formatter, this is appears in files views (see screenshot)

Steps to reproduce

Go to /admin/structure/views/view/files
Click File: Filename, under Fields.

Proposed resolution

Extend parent settings and unset the link_to_file option as it will be by default true $settings['link_to_file'] = TRUE; and will not be used in this formatter.

Problem/Motivation

Issue fork drupal-3116382

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

Odai Atieh created an issue. See original summary.

odai atieh’s picture

StatusFileSize
new723 bytes
odai atieh’s picture

Status: Active » Needs review

Status: Needs review » Needs work

The last submitted patch, 2: 3116382-2.patch, failed testing. View results

swatichouhan012’s picture

Status: Needs work » Needs review
Issue tags: +VbContribution2020
StatusFileSize
new1.18 KB
new768 bytes

Status: Needs review » Needs work

The last submitted patch, 5: 3116382-5.patch, failed testing. View results

odai atieh’s picture

@swatichouhan012
No need for "link_to_file" checkbox to be displayed, so I added unset($form['link_to_file']);.

File link formatter should be link so $settings['link_to_file'] = TRUE; shouldn't be changed.

hardik_patel_12’s picture

Issue summary: View changes
StatusFileSize
new1.15 KB
new793 bytes

@Odai Atieh Link this field checkbox is not appearing , tried to handle that and removing duplication of settings. Kindly review the patch

hardik_patel_12’s picture

Status: Needs work » Needs review
odai atieh’s picture

Status: Needs review » Needs work

The last submitted patch, 8: 3116382-8.patch, failed testing. View results

odai atieh’s picture

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

hardik_patel_12’s picture

Status: Needs work » Needs review
Issue tags: +Bug Smash Initiative
StatusFileSize
new894 bytes
new548 bytes

Kindly review a new patch.

quietone’s picture

Issue summary: View changes
Status: Needs review » Needs work
Issue tags: +Needs tests

I tested this on 9.2.x and can confirm the patch works.

As always this will need a test.

mohit_aghera’s picture

Version: 8.9.x-dev » 9.2.x-dev
Status: Needs work » Needs review
Issue tags: -Needs tests
StatusFileSize
new3.26 KB
new3.12 KB
+++ b/core/modules/file/src/Plugin/Field/FieldFormatter/DefaultFileFormatter.php
@@ -32,7 +32,13 @@ public static function defaultSettings() {
+      '#default_value' => !empty($this->options['link_to_file']),

Spotted one issue while writing test cases that value is not getting saved when we change the value.
Fixed issue in current patch.

Added test cases to ensure that no additional fields are present.
Added test case for other field formatter related configurations to ensure that checkbox field works as expected..

mohit_aghera’s picture

StatusFileSize
new2.39 KB

Adding test-only patch for reference.

mitthukumawat’s picture

StatusFileSize
new71.26 KB
new67.78 KB

The patch #16 applied successfully and the field formatter is not longer showing twice in files view configurations.
Adding screenshots for reference.
RTBC+1

Status: Needs review » Needs work

The last submitted patch, 17: test-only-3116382-17.patch, failed testing. View results

mohit_aghera’s picture

Status: Needs work » Needs review

Changing to needs review as failures is due to test-only patch.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

vikashsoni’s picture

StatusFileSize
new60.42 KB
new43.81 KB

patch #14 working fine and applied successfully
After patch field formatter is not showing with twice

Thanks for the patch
For ref sharing screenshot ...

hmendes’s picture

Status: Needs review » Reviewed & tested by the community

The patch from #16 worked for me on Drupal 9.4.x

Steps:

  • Followed the steps provided in the IS
  • Saw the problem
  • Applied the patch
  • Followed the steps provided in the IS
  • The first Formatter field is gone

The Test-only patch shows the problem and the patch fix it, so changing this to RTBC.
I'll not provide prints as it is basically the same from #18 and #23.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work

I'm not sure this fix is correct. The \Drupal\file\Plugin\Field\FieldFormatter\DefaultFileFormatter widget is used in more contexts than just views. For example, entity displays. This formatter is supposed to always link to a file. As far as I can see it is not meant to be optional. The description of the formatter is:

Formatter for a text field on a file entity that links the field to the file.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

mohit_aghera’s picture

Status: Needs work » Needs review

I've debug the issue further.
Duplicate form is appearing because we are returning $form in the field formatter.
When call comes to field formatter, it already has all the options in the form. See https://git.drupalcode.org/project/drupal/-/blob/11.x/core/modules/views...

Once we return $form as it is, it gets merged into existing form array.
Line 540-542 https://git.drupalcode.org/project/drupal/-/blob/11.x/core/modules/views...

This is causing the duplicate form fields.

I believe returning empty array should fix the problem.

smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs issue summary update

Left some comments after reading #30 but am tagging for summary update as proposed solution doesn't seem to line up.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.