With #2187837: Bring media element and field widget inline with managed_file equivalents the UX / Workflow how to add a file to a file field through the media browser has changed.

Before it worked like that:

1. Click add another item
2. Press Select for opening the media browser
3. Select a file / image
4. Press Submit
Repeat 1 -4 for adding another image
5. Save the content

Screenshot old file field browsing

Now like that:

1. Click Browse for opening the media browser
2. Select image / file
3. Submit
4. Press Attach
Repeat 1 - 4 for adding another image / file
6. Save the content

Screenshot new fielfield browsing

So the amount of steps is basically the same. But the user is not getting the concept in my case. It is not clear and regularly forgotten to press "Attach" If you just save the content nothing is attached and the new image you wanted to add is lost.

Is it possible to attach the file at once after pressing the "Submit" button in the media browser? (So we would have on step less, which is always good). And / or can the attach be triggered on saving the content? So if someone forgets to "Attach" the images / file is saved anyway.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Dave Reid’s picture

I'm confused why there's the additional step as well. If the intent was to make it work more like the core File or Image fields, I don't understand. They don't have the concept of two submissions.

Devin Carlson’s picture

Status: Active » Needs review
FileSize
1.37 KB

This functions the same as file.module's managed_file form element: you choose a file (local machine/media browser) and then upload/attach the file. This allows users to select a different file before uploading/attaching it in case they chose the wrong one by mistake.

On the code side "attaching" the file allows all of the validation, access, previews, etc to happen on the backend instead of through JS which makes development a lot easier, makes testing possible and allows the field widget to be used with JS disabled.

As with the managed_file form element, the file will still be attached if the user presses the submit button without first attaching the file. I'd suggest filing a bug report with steps to duplicate the issue as there is currently a test for this in media.test:

        $test_file = $this->getTestFile('text');
        $test_file->uid = $this->admin_user->uid;
        $test_file = file_save($test_file);
        $path = 'media/test/' . $tree . '/' . $extended;
        $input_base_name = $tree ? 'nested_media' : 'media';

        // Submit without a file.
        $this->drupalPost($path, array(), t('Save'));
        $this->assertRaw(t('The file id is %fid.', array('%fid' => 0)), 'Submitted without a file.');

        // Submit a new file, without using the Attach button.
        $edit = array('media[' . $input_base_name . ']' => $test_file->fid);
        $this->drupalPost($path, $edit, t('Save'));
        $this->assertRaw(t('The file id is %fid.', array('%fid' => $test_file->fid)), 'Submit handler has correct file info.');

That said, I initially included the JS required to automatically attach the file once it has been selected in the media browser but I removed it in order to be consistent with the managed_file element. The attached patch restores the automatic attach if that's the consensus. :)

It would also be simple enough to make this configurable per field instance if that was desired.

marcusx’s picture

Seems that there are very good reasons for the change. (Non js functionality, testable, etc.) If files should not be 'auto attached' by default adding at least a configuration option sounds sensible.

But at the moment the widget is also not useable because of #2215905: Media browser widget for file field adds a operations column for every row and I am also using Media Multi-select https://drupal.org/sandbox/fangel/1652676 which is broken due this change as well. Opened already #2216273: Latest media changes break the multiselect. So UX is the most minor issue for me at the moment. Although it got the most attention.

For now I use a cherry picked version of media without these changes but with the patches I needed for proper ckeditor integration. I try to look into the other issues first and can help with this one later if there is a conclusion that we want to have it configurable.

vegardjo’s picture

I'm also missing the possibility to edit a file entity on a node form. I made a new issue, but I belive it is related to this as it happened after upgrading: #2217061: Edit options on imagefield missing

jmuzz’s picture

If I understand correctly, the requirement for the user to be able to choose a different file is to cover the case when they click on the wrong thing in their browser's file chooser. If that's the case, they can already choose a different file before they upload, they just need to do it in the media browser popup instead of on the node edit page. I am in favor of the auto attaching. It seems unnecessary for the user to have to confirm their file in both the media browser and the node edit form.

ParisLiakos’s picture

Issue tags: +7.x-2.0 beta blocker
hefox’s picture

Patch is being used on a project with multiple testers/developers and has not presented any problems yet and has provided the desired functionality

Yuri’s picture

Confirming that patch #2 is working.

seworthi’s picture

Confirming patch works as advertised. RTBC

seworthi’s picture

Status: Needs review » Reviewed & tested by the community

  • Commit fe09f09 on 7.x-2.x by aaron:
    Issue #2216329 by Devin Carlson: New filelfield browser widget is...
aaron’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

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