Problem/Motivation

When the default field behavior is set to not display files, the default is not respected on the content creation page.

  1. Install Drupal with minimal profile.
  2. Enable Field UI and File modules.
  3. Create a content type.
  4. Add a file field to the content type.
  5. Check "Enable Display field" and leave "Files displayed by default" unchecked.
  6. Go to the content creation page and upload a file.

Expected result: "Include file in display" is unchecked.
Actual result: it is checked.

Proposed resolution

Fix the bug. Make the field follow the default as set in the content type.

Remaining tasks

Needs Review. Possibly a manual test with a screenshot.

User interface changes

none.

API changes

none.

Beta phase evaluation

Reference: https://www.drupal.org/core/beta-changes
Issue category Bug
Unfrozen changes Unfrozen because it only changes code to fix a bug that also exists in Drupal 7
Prioritized changes The main goal of this issue is usability.
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

David Lesieur’s picture

Version: 7.12 » 7.x-dev
Status: Active » Needs review
FileSize
608 bytes
bskibinski’s picture

Tested the patch from #1 and it seems te work perfectly!

carsonw’s picture

Status: Needs review » Reviewed & tested by the community

The patch from #1 is simple and sweet, and it works perfectly. Can we get this committed to core?

David_Rothstein’s picture

Version: 7.x-dev » 8.x-dev
Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs backport to D7

This looks very reasonable, but needs to go into Drupal 8 first.

It also seems like there should be tests?

swentel’s picture

Component: file system » file.module
pawel.traczynski’s picture

I tested patch from #1 and it works for me.

Can you move this to D7 core please? :) Let add it into D7 instead of having system where some things are broken ^^

chrisfromredfin’s picture

Issue summary: View changes
Status: Needs work » Needs review
FileSize
596 bytes

Let's see if this change breaks anything in the current D8 test suite. Then we'll write a test for this case (I'm not super up on how to write tests so don't want to wait to get this small piece moving along regardless.)

Status: Needs review » Needs work

The last submitted patch, 7: 1520716-file_displayed_checkbox-7.patch, failed testing.

lokapujya’s picture

Assigned: Unassigned » lokapujya
Status: Needs work » Needs review
FileSize
2.27 KB

Modified the File Field Display Test.

Still need to get the FileFieldRSSContentTest to work.

lokapujya’s picture

Assigned: lokapujya » Unassigned

Status: Needs review » Needs work

The last submitted patch, 9: 1520716-9.patch, failed testing.

lokapujya’s picture

Status: Needs work » Needs review
FileSize
2.83 KB

Rerolled. Plus, progress on a fix for FileFieldRSSContentTest.

Status: Needs review » Needs work

The last submitted patch, 12: 1520716-12.patch, failed testing.

lokapujya’s picture

Status: Needs work » Needs review
FileSize
1.13 KB

Maybe the original tests were ok.

lokapujya’s picture

14: 1520715-14.patch queued for re-testing.

carsonw’s picture

I can't believe the patch in #1 hasn't been committed to D7 core yet. I have to apply it every time I upgrade Drupal. Can we please get it committed?

lokapujya queued 14: 1520715-14.patch for re-testing.

Status: Needs review » Needs work

The last submitted patch, 14: 1520715-14.patch, failed testing.

lokapujya’s picture

Issue tags: +Needs reroll, +Needs tests
lokapujya’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll, -Needs tests
FileSize
2.58 KB
1.47 KB

Status: Needs review » Needs work

The last submitted patch, 20: 1520716-test-only.patch, failed testing.

lokapujya’s picture

Status: Needs work » Needs review
jhedstrom’s picture

Can somebody update the issue summary? The patch in #20 still applies.

lokapujya’s picture

Issue summary: View changes
Issue tags: -Needs issue summary update
lokapujya’s picture

Issue summary: View changes
lokapujya’s picture

Issue summary: View changes
jhedstrom’s picture

+++ b/core/modules/file/src/Plugin/Field/FieldWidget/FileWidget.php
@@ -349,11 +349,16 @@ public static function process($element, FormStateInterface $form_state, $form)
+      if(isset($item['display'])) {
+        $display_value = $item['display'] ? '1' : '';
+      } else {

There's a spacing issue between the 'if' and the opening parenthesis here.

Also, since isset($item['display']) is already being called, the line below can probably be simplified to '#value' => $item['display'].

lokapujya’s picture

$item['display'] is a boolean, the display value is '1' if checked.

jhedstrom’s picture

Issue summary: View changes
Status: Needs review » Reviewed & tested by the community

This fixes a bug that also exists in Drupal 7.

I've updated the issue summary to include a beta phase evaluation.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/modules/file/src/Tests/FileFieldDisplayTest.php
@@ -93,4 +93,30 @@ function testNodeDisplay() {
+    // Create a new node with the uploaded file.
+    $nid = $this->uploadNodeFile($test_file, $field_name, $type_name);
+
+    $this->drupalGet('node/' . $nid . '/edit');
+    $this->assertNoFieldByXPath('//input[@type="checkbox" and @name="' . $field_name . '[0][display]" and @checked="checked"]', NULL, 'Default file display is off.');

It looks like we also need an assertion that the expected display is there if the setting is changed. Just having an assertNoFiledByXPath is prone to creating false positives.

lokapujya’s picture

Status: Needs work » Needs review
FileSize
2.76 KB
948 bytes

Very good point. Do you like this better?

jhedstrom’s picture

Since the test changed, could you re-attach that as a separate patch to show current failures?

lokapujya’s picture

FileSize
1.62 KB

Test only to show the fail.

Status: Needs review » Needs work

The last submitted patch, 33: 1520716-33-test-only.patch, failed testing.

jhedstrom’s picture

Status: Needs work » Reviewed & tested by the community

I think the patch in #31 addresses the concerns in #30. The patch in #33 is the test only and was expected to fail. Back to RTBC I think.

alexpott’s picture

Version: 8.0.x-dev » 7.x-dev
Status: Reviewed & tested by the community » Patch (to be ported)

Yep I do prefer #31 - nice work @lokapujya. Committed d6be512 and pushed to 8.0.x. Thanks!

Thanks for adding the beta evaluation to the issue summary.

  • alexpott committed d6be512 on 8.0.x
    Issue #1520716 by lokapujya, cwells, David Lesieur: "Files displayed by...
lokapujya’s picture

Assigned: Unassigned » lokapujya
lokapujya’s picture

Status: Patch (to be ported) » Needs review
FileSize
1.36 KB
1.95 KB

and the D7 versions.

lokapujya’s picture

Status: Needs review » Needs work

forgot something.

lokapujya’s picture

Status: Needs work » Needs review
FileSize
1.51 KB
2.1 KB

Changed the tests as we did in the D8 patch.

The last submitted patch, 39: 1520716-39-test-only.patch, failed testing.

The last submitted patch, 41: 1520716-41-test-only.patch, failed testing.

lokapujya’s picture

Assigned: lokapujya » Unassigned
djdevin’s picture

Status: Needs review » Reviewed & tested by the community
FileSize
2.22 KB

Re-rolled and RTBC.

Edit: to review but...really should be RTBC after this.

djdevin’s picture

Status: Reviewed & tested by the community » Needs review
lokapujya’s picture

Status: Needs review » Reviewed & tested by the community

Tested. I removed the fix and verified that the test fails without the fix, too.

David_Rothstein’s picture

Status: Reviewed & tested by the community » Fixed
Issue tags: +7.40 release notes

Committed to 7.x - thanks!

  • David_Rothstein committed c515c14 on 7.x
    Issue #1520716 by lokapujya, djdevin, David Lesieur, cwells, jhedstrom...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

sksshed’s picture

I know this was a couple of years ago but I am having the same issue, was the patch realised into Drupal 7 core?

David_Rothstein’s picture

Yes, this was committed in October 2015 and included in Drupal 7.40 and above.

I tested now and it still works for me in the latest Drupal 7 release. If it isn't working for you, please create a new issue with details on how to reproduce the problem (and link to it from here). Thanks!