Closed (fixed)
Project:
Drupal core
Version:
8.7.x-dev
Component:
media system
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
30 May 2017 at 15:25 UTC
Updated:
28 Jan 2020 at 08:33 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
marcoscanoComment #3
marcoscanoComment #4
slashrsm commentedI think that the field needs to stay required (this won't affect only the form element but also the entity validation). Entity can't be without the name.
Recently, on a client project, we solved this by making the form element non-required in a form alter. Then we added an entity builder callback that checked if the name was provided and triggered the auto logic if not. This ensured that the name was always there for the entity validation. Maybe core could use a similar approach?
Comment #5
phenaproximaRe-tagging.
Comment #6
xjmComing here from #2831940: Create file field widget on top of media entity. Rather than making the field optional and defaulting to some arcane combination of tokens and UUID, I'd suggest doing something like what we do for field names or block machine names, where the name defaults to the name of the thing in the source field (for local media, the filename). The UI could work like these do, with a generated default but a link to customize it:
For remote media, maybe the plugin could provide its own default name.
Comment #7
marcoscanoJust a small precision: the uuid-based default name is only used as a very last resource.
"Normal" plugins should provide sensible default names. Image/File from core already provide the filename as the default name, and remote-media source should also use some metadata attribute (such as the video title, author, etc) as a default option.
The default fallback will only be used if some contrib/custom plugin doesn't provide a specific name, which shouldn't happen that often.
Comment #8
wim leers#4 I agree that the field should remain required. The solution you describe seems simple & pragmatic.
#6: That feels like a nice to have, for the reasons given in #7.
#7: this totally makes sense :)
I don't think this is a feature, I think this is pretty much required for a remotely usable Media system.
Comment #9
xjmI don't think we should form alter the field to be not required. I think we should present the user with the default name and give them the opportunity to change it, like we do elsewhere in core. We already have UI patterns for this.
Comment #10
pk188 commentedRe rolled the patch as it failed to apply.
Comment #11
pk188 commentedAgreed with #8. So changing status again to "needs work".
Comment #12
wim leers#9 AFAICT we don't have a pattern for this. The screenshots in #6 do not apply to the use case here. The two examples you give merely generate a default machine name that the user can choose to edit. The user still must type an actual name.
In the case of Media, no default name can be generated until a file is uploaded (or for remote media: until a URL is pasted). That means no name until that action has been performed. Which is why @slashrsm in #4 explains the name is optional in his project, and if it isn't provided, a name is generated based on the uploaded file.
Comment #13
berdirExactly, this is different from anything we have so far with machine names or so.
Something I experimented a bit in Pathauto (with mixed success/user feedback but that's also because it still is required there) is moving the name/label field at the bottom of the form, so users provide file/URL (pattern in pathauto) *first*. In that case, we might be able to add some custom JS/ajx that fills the name field with the default suggestion. But we might want to make small improvements here instead of blocking everything on some idea that might be more complicated to implement?
Comment #14
wim leersThat's exactly what I was thinking too :)
Something like:
With that entire last bit in smaller font size, perhaps even faded to the background a bit, to make it visually clear it's A) not important, B) optional.
+1
Comment #15
xjmRight, but in this case, the default name comes from the uploaded file. So the machine name JS would follow that, rather than a user-entered text field. It's the same in that the user is providing a file which provides the default, and then they have an option to change it. But #14 sounds kind of like what I'm suggesting anyway.
This is what I mean about using the existing machine name pattern. The default is in a small font size. You can click the link to change it. Just like with the machine names.
Comment #16
xjmThe uploaded file is a required field, just as the Label for the field and block above is a required field. The machine name link does not appear until you fill in the required field. It's the same pattern.
Comment #17
wim leersHm, it's indeed more similar than I first thought. But the examples in #6 do not have
'#required' => TRUE, which you've been stressing.Also, I thought I remembered that the ability to interact with
input[type=file]was limited in JavaScript. Turns out it's A) mostly about manipulating those inputs via JS, B) the necessary APIs have indeed only been added in the last 5-7 years: https://www.html5rocks.com/en/tutorials/file/dndfiles/ — which means I'm remembering limitations that aren't limitations anymore :)It seems like we're pretty well aligned here! :)
Comment #18
marcoscanoSo far we were relying on an empty name field to trigger the whole default-name-generation logic. This ensured any user input wasn't overriden by this logic. With the JS/AJAX approach from #6 and #14, this might be very hard to maintain. Are we going to disregard any existing user input and re-calculate the default suggested name after any change on the source field?
In other words:
- User uploads file
final_report_version_2017JAN27_2_final.pdf.- We auto-generate a media name called
final_report_version_2017JAN27_2_final.pdf.- The user doesn't like the default name, clicks on "edit" to change it, and then gives the media item the name:
My Great Report, and saves the form.- Later on the user edits this media item and uploads another file
final_report_version_2017JAN27_2_final(2).pdf, after deleting the previous one.-> How are we going to detect if this file upload should or should not generate (and fill) the media name?
Comment #21
seanbWe have metadata mapping to allow changes in the source field to change existing data. In #2933012: Expose the filename as metadata for file based media sources, a patch was added to add a name metadata attribute for file based media sources.
For remote video's (that already have the name field hidden by default) we've added to the field map to fix this in #2983325: Use title -> name mapping for the "Remote video" type.
We could do the same for all other media types once #2933012: Expose the filename as metadata for file based media sources lands.
Comment #22
marcoscano+1 to #21, as long as we don't change existing sites :) (which I don't think was the idea anyway, but just in case :P)
Comment #24
seanbSo #2933012: Expose the filename as metadata for file based media sources has landed. Time to continue here.
This is a first patch to hide the media name by default for new sites and map the media source name/title to the media name base field. Let's see how many tests will need fixing.
Comment #26
seanbFixed the tests. Not sure if we need more tests for the standard configuration? We have tests with media types showing the name field in the form, we also have the display test running against the standard profile showing the default name is no longer present for the image/file media types.
Comment #27
phenaproximaWe should add an assertion that the media name appears on the next page -- we need to be certain that the default name is actually used.
Remote video works very differently under the hood than file-based media items, so ideally we would test this change for every media type that ships with core, individually. But we can do that in a follow-up; I think, for this issue, let's just make sure remote video is explicitly tested, since it's the outlier.
Comment #28
chr.fritschIn Drupal\Tests\standard\Functional\StandardTest we are checking this:
Now we don't have a name field anymore, so we could change this to $this->assertSession()->fieldNotExists()
Comment #29
seanb#27
1. Fixed.
2. Fixed. Added MediaStandardProfileTest to test the standard profile form configuration, creation, field mapping and display configuration. We could expand on that in the future. See if we can move/remove the media specific code in
Drupal\Tests\standard\Functional\StandardTestand see what we want to do withDrupal\Tests\media\FunctionalJavascript\MediaDisplayTestsince there is some overlap.#28
Fixed for now, but as mentioned above we might want to move those tests to the media module.
Comment #30
marcoscanoWhile I think an ideal solution for some types (specifically the remote video) would be to pre-populate the field while still allowing it to be edited, I understand this is not in scope of this issue, and this is definitely a good step in the direction of making all media forms more usable.
So +1 from me.
Comment #31
phenaproximaNice work!
This needs @inheritdoc.
I think we can use $assert_session->elementCount() here. The selector also seems a little bit brittle; can we use a CSS class to target that inner element?
We can get the source attribute in one shot: $assert_session->elementExists()->getAttribute('src').
Why aren't we doing all the other assertions here too?
Comment #32
seanb#31
1. Fixed.
2. We want to assert there is only 1 child element, so more specific CSS might pass while it shouldn't. While thinking about it, testing for DIV elements only could also pass while it shouldn't. Changed it to * to match alle child elements.
3. Fixed, removed the
$page->find()part.4. Fixed, you are right, there is value in asserting all other elements updated as expected.
Comment #33
chr.fritschThanks @seanB.
I am removing the "Needs tests" tag, because we have plenty of new tests.
I think this is ready to go!
Comment #35
chr.fritschTestbot hickup
Comment #36
chr.fritschSorry, I have to reject this. The patch currently does not remove the name field from the media library form displays.
Comment #37
seanbWorking on this
Comment #38
seanbAlso removed the name from the media library form as mentioned in #36. When we do this all media types except 'image' will not have any fields a user needs to fill. I chose to add the media name as an item element when the name field is hidden, so the users see a confirmation the right file with the right name has been uploaded.
Comment #40
seanbThis should fix the tests.
Comment #41
sreher commentedI am reviewing this on DrupalEurope and I am mentored by @ericheydrich
Comment #42
sreher commentedWhat I did:
* enable media and media library module
* add media field to the content type
Upload media to the article
* image - alt field required
* pdf - no field
Upload a remote video to media library
* youtube - no field
* mp4 - no field
I checked:
* Medial Library in the backend
* Entity Reference Field
The name of the file will be used as the name of the media entity. The name is not editable.
It is possible to change the visibility of the name field. You can enable it in the media types manage form display settings. After that the name is editable.
Comment #44
seanbTriggering the test again, not sure what happened.
Comment #45
phenaproximaThis patch looks great to me.
My only concern with MediaStandardProfileTest is that there are multiple test methods, and each one is installing Standard. That is going to be one hell of a slow test class.
Maybe we could refactor it so that we have one public test method (and thus Standard is only installed once), yet keep the code clean by making all the current test methods into private helpers which are called from the main test method. Thoughts?
Comment #46
chr.fritschMoved all the testcases into one method.
Comment #47
phenaproximaI think this is done, then!
Comment #48
alexpottI've manually tested this. It makes uploading files to media much much nicer. Not having to provide a name when the file already has a name makes sense.
The added test coverage looks very complete. Nice work.
Comment #49
alexpottComment #52
weynhamzSorry for buzzing on a closed issue. I am interested in the method in comment #4, is there a patch already?