Problem/Motivation
From comment #2:
There're a lot of classes being added in
media_library_preprocess_media,Drupal\media_library\Form\AddFormBase,Drupal\media_library\Plugin\Field\FieldWidget\MediaLibraryWidgetandmedia--media-library.html.twig.
The module markup is supposed to only include classes that are used for providing functionality.
Proposed resolution
Move all representational classes to Classy and assure that any representational markup is overridable at the theme level.
Remaining tasks
Review
User interface changes
None
API changes
Classes added in the Media Library module are moving to classy. Other themes will need to add their own representational classes or copy those from Classy.
Data model changes
none
Release notes snippet
| Comment | File | Size | Author |
|---|---|---|---|
| #118 | 3087456-118.patch | 79.51 KB | phenaproxima |
| #117 | 3087456-117.patch | 79.51 KB | phenaproxima |
| #116 | interdiff-3087456-115-116.txt | 1.23 KB | phenaproxima |
| #116 | 3087456-116.patch | 79.42 KB | phenaproxima |
| #115 | interdiff-3087456-113-115.txt | 1.79 KB | phenaproxima |
Comments
Comment #2
lauriiiThis opens a big can or worms. There's a lot of classes being added in
media_library_preprocess_media,Drupal\media_library\Form\AddFormBase, andDrupal\media_library\Plugin\Field\FieldWidget\MediaLibraryWidget. There's also no templates for a lot of the markup so moving these to Classy wouldn't be straightforward.I'm fine with keeping the classes added in Views as they are, but the classes that we're adding in Form API and preprocess function should be moved to Classy.
Comment #3
phenaproximaThis should fix all instances of
'#type' => 'container'in AddFormBase.Comment #4
lauriiicontainer__media_library_add_form__fieldswill create two different suggestions:container__media_library_add_formandcontainer__media_library_add_form__fields. I don't think anyone would ever use thecontainer__media_library_add_formsuggestion because these are completely independent elements.Comment #5
phenaproximaOops! Good point as always, @lauriii :)
This should fix that problem. It also addresses the rest of the
'#type' => 'container'instances of this snafu that I found in this module. No interdiff because it would be bigger than the patch.Comment #6
phenaproximaAddressed most of the instances of
'#type' => 'html_tag'. I know I'm creating a lot of templates here, but the plan here is to overshoot the mark if necessary, fix the tests, then dial things back.Comment #7
phenaproximaFixed every input element, container, and HTML tag in MediaLibraryWiget.
Comment #10
phenaproximaOK -- I think this completely fixes AddFormBase, FileUploadForm, OEmbedForm, and MediaLibraryUiBuilder. It also removes a lot of templates; I was able to move them to preprocess functions in Classy, which honestly seems like a better place for them, and cuts down the size of the patch considerably.
Comment #12
phenaproximaI think this moves or otherwise abstracts away just about opinionated CSS class that can be moved or abstracted away, including in media_library.module. Not sure if I've overreached the scope, but as I previously said, I'm just firing everything I have at this, more or less, and we can refactor later.
This is definitely still buggy and will definitely fail tests, but it's a start.
Comment #13
phenaproximaHere's a little self-review, and a "guide" of sorts to this patch for the next person who looks at it.
I shouldn't have moved this line into Classy. It needs to be moved back.
This is new class, but updateFormCallback() was previously targeting the representational one.
This doesn't actually work; it's a temporary hedge. There's doesn't seem to be any way except #prefix and #suffix to wrap the message in a P tag, so this might just need its own template, sadly.
The .media-library-add-form__media part of the modified selector was redundant anyway. Nothing else gets the data-media-library-added-delta attribute.
This isn't so nice. I'd rather give FileUploadForm and OEmbedForm unique form IDs and implement hook_form_FORM_ID_alter in Classy.
But, since they share some opinionated classes with AddFormBase, what might be better is for AddFormBase to implement BaseFormIdInterface as well. This might result in a change record, but it should be completely backwards-compatible. And besides, Media Library is still experimental :)
This also doesn't work and might need its own template. Which totally sucks, but unless we're allowed to use #prefix and #suffix to inject opinionated classes, I'm not sure if we have another option.
This is also messed up. There is still no template in core that can just freaking slap some content into a button tag. (WTF!) But I'm not entirely sure how to fix this yet. I would rather not create a whole template just for this...
In manual testing, I established that the media-library-views-form class is being applied by Classy. So it's not needed here. :)
Same thing here.
Comment #14
oknateAddressing #13:
1. ✅ Moved
$variables['metadata_attributes'] = new Attribute();back.2. 👍
3.This seems to work OK, it’s just the text needs to be wrapped in markup element.
4. 👍
5. Still @todo
6. This seems to work OK, it’s just the text needs to be wrapped in markup element.
7.This seems to work OK. There was a bug in twig. I think to remove the attribute, it needs to be like this:
{% attributes.removeAttribute('name') %}8. 👍
9 .👍
Comment #15
phenaproximaThanks, @oknate! Those changes look good to me, and indeed they do fix some problems I was having. :)
In this patch, I put BaseFormIdInterface on AddFormBase and its children. This makes the required modifications substantially cleaner.
As for the "No media items selected" text in the field widget, I wasn't able to get that into an opinionated P tag any way except #prefix and #suffix. IMHO this should be acceptable, since it is still overridable -- just not easily by themes. Custom modules can do it in a jif, though, with hook_field_widget_WIDGET_TYPE_alter(). (That hook really should run for themes, too, but that's not in scope here.) That allowed me to get rid of another template. We're down to only one new template, and maybe we'll find a way to eliminate that too.
At this point, I'd like @lauriii to validate the approach we're taking here and point out any glaring flaws we may have missed. If he's good with what we're doing here, we can go about fixing the tests.
Comment #16
phenaproximaOne major thing still outstanding: I am encountering an ugly bug when adding new media in the modal. Each thing has two "remove" buttons -- one styled correctly, the other wildly messed up. I can't figure out why this is happening.
Comment #17
phenaproximaThis patch fixes the ugly bug (turned out to be me using
#themewhere I should have used#theme_wrappers). It also removes virtually all the #theme_wrappers overrides from AddFormBase and its children in favor of three hook_form_alter() implementations in Classy, which is much cleaner and less complicated overall, IMHO.The field widget and MediaLibraryUiBuilder remain the more "troublesome" ones, because there is no way for the theme to influence their output.
Comment #18
phenaproximaManaged to remove a couple more
#theme_[wrappers]overrides in FileUploadForm and OEmbedForm.Comment #19
phenaproximaHere's a little brain dump, primarily directed at @lauriii, about the current state of this patch.
container__media_library_add_form_blahblahblah) is cumbersome, significantly less discoverable, and will be a worse experience for developers and themers. Sure, render arrays are somewhat unreliable, but that's a fundamental problem with render arrays. They're what we're stuck with, so IMHO let's alter them in whatever way is least painful.$form_object instanceof Foo). And that just sucks. So, to me, adding BaseFormIdInterface and changing the form IDs of FileUploadForm and OEmbedForm is a small BC break in a currently experimental module...but it's a BC break worth making. Otherwise, we're permanently saddled with a confusing, non-standard form alter mechanism that sucks.media_libraryin code, andmedia-library.html.twigin themes). It seems a bit "heavy", and it would allow themes to maybe impose more opinions than we'd like; after all, Media Library is meant to be opinionated and not terribly extensible. But it might also be the "right" way to do this. I'll defer this decision to committers.Comment #20
oknateAnother brain dump. I didn't understand why we needed the one template, and couldn't just use a preprocess hook. @phenaproxima explained this to me on slack.
Me: "I don’t understand why we need that one template."
"does this not work?"
phenaproxima:
Comment #21
oknateRegarding this:
If it is discouraged, is there a way to use it but mitigate the downsides? Maybe adding comments that this should only be used for adding classes and minor markup changes, and that if not used carefully, it could break Media Library functionality?
Comment #22
oknateI have manually tested #18 and everything looks good visually and functionally. I think the code changes make sense too. I think this is ready, AFAIK.
Comment #23
oknateIssue summary update to encompass the larger scope other than the one file.
Comment #24
oknateComment #25
phenaproximaFound a way to remove the awkward
input__submit__media_library_toggle_weightpseudo-template and the hard-coded prefixing/suffixing around the widget's empty text. The upshot is that I had to exchange the removed template for a different, but more useful, pseudo-template wrapping the entire media library widget, and go back to using'#type' => 'html_tag'for the weight toggle button.I think that's okay in this case, though, because:
<button>STUFF</button>template, I would argue that this is a legitimate, functional use of'#type' => 'html_tag'.classy_preprocess_fieldset__media_library_widget().The only reason I have a new
fieldset--media-library-widget.html.twigtemplate in this file is because both of these things are put into the fieldset prefix, which is wrapped by a <span> tag, and because I am a good HTML citizen, I didn't want to put a P inside a SPAN.Comment #27
phenaproximaNice job, MediaLibraryTest! #25 caught a legitimate problem --
Drupal.behaviors.MediaLibraryWidgetToggleWeightis not tolerant of the surrounding markup being changed. Should be fixed in this patch.Comment #28
phenaproximaTagging for front-end framework manager review.
Comment #29
phenaproximaSomething for committers to consider, since this is technically blocking Media Library from being marked stable...
Even though the approach we're taking (so far) is probably a bit on the hacky side (pseudo-templates everywhere...), we might consider this as a short term fix for the immediate problem -- namely, that Media Library is outputting render arrays peppered with representational CSS classes -- then file follow-up issues, possibly to be resolved by beta (or in another minor feature release, if possible), to add dedicated templates and increase the overall themeability.
Potentially, something like #3065677: Create a media_library form element could be a long-term solution.
Comment #30
seanbI’m not a very good themer, I guess I can’t really say to much about it. All approaches seem a bit yuck to me. I don’t see a good way around it though? And I understand why we need it. Apparently it is really hard to make Drupal output exactly what you want. That doesn’t seem to be something we can fix in media library 😞
Comment #31
phenaproximaYou're not wrong. This is why I'm pushing for us to use hook_form_alter() in this patch -- through it, I was able to remove a lot of the pseudo-theme hooks.
I'm starting to think that having MediaLibraryUiBuilder::buildUi() output through a new
'#theme' => 'media_library'theme hook would be a good idea (and not that hard to implement). Another option would be to essentially implement #3065677: Create a media_library form element now, which would probably increase the themeability too.The field widget remains the real challenge. I don't know if there is a pre-existing pattern in core for making a field widget completely themeable. I took at look at FileWidget, for example -- it outputs a #managed_file element, which is themeable to an extent, but not totally customizable without writing a custom module to implement hook_field_widget_form_alter().
This is kind of why I really want to discuss with @lauriii before going further. How themeable do we really need to be, in order to be on par with the rest of core?
Comment #32
phenaproximaI decided to proceed with making the output of MediaLibraryUiBuilder::buildUi() more themeable. To that end, I added a new theme hook (
media_library) and simple template. This allowed me to merge a couple of preprocess functions in Classy, except for one which cannot be removed due to the way MediaLibraryUiBuilder responds to AJAX requests (it intentionally doesn't return all the "chrome" of the UI when switching between media types, thus necessitating a pseudo-theme hook to target the content of the UI, rather than the whole thing).Comment #34
phenaproximaThis will fix the tests.
Comment #35
phenaproximaMoved all the Classy stuff in #34 to Seven, after discussion with @seanB, @alexpott, and @lauriii. The latter will follow up in this issue to summarize. I expect this patch to fail tests enormously; MediaLibraryTest will need to be changed so that it no longer uses CSS classes which are found, as of this patch, only in Seven. (It will also have to test everything against both Seven and Classy.)
Comment #36
phenaproximaWhoops! Sorry, #35 accidentally included an unrelated change.
Comment #37
lauriiiI discussed the proposed approaches with @phenaproxima, @seanB, and @alexpott. The current proposed solution moves the classes to preprocess functions and form alters in Classy. However, a lot of the classes are specific to Seven, and wouldn't be necessarily needed by other themes. Given that the whole purpose of Classy was to improve TX by moving all classes from preprocess functions and forms to templates, it doesn't seem sensible to add these classes this way. Also, making these changes to Classy would make them an API, and we couldn't really make improvements to this later. Therefore we thought it would make the most sense to move these to Seven.
Moving classes to Seven could make it more difficult for some themes to do a minimal implementation of the designs which is to just copy what Seven is doing. However, some of that could be mitigated by creating a contrib project that provides the Seven styles to all themes. This way it could be used in the frontend theme as well.
There's already a follow-up to try to make API changes to Drupal that would solve this problem: #2195695: Admin UIs on the front-end are difficult to theme.
Comment #39
xjmThis issue is a potential contrib blocker for making it easy for themes to support Media Library.
Comment #40
effulgentsia commentedComment #41
effulgentsia commentedPerhaps a good next step here is to propose which CSS class additions belong in Seven and do not belong in Classy, and why?
Comment #42
phenaproximaLucky 42.
This won't pass all tests yet, but it will fix several of the failures.
I spent some time pairing with @lauriii today on this. It seems that we're going to go piece by piece and figure out what should be in Seven, what should be in Classy, and what should be converted to a template/theme hook of its own. I put todos in the patch to record our decisions.
Be forewarned: the final version of this patch will be long and complex due to the sheer number of small changes required to MediaLibraryTest.
Comment #44
phenaproximaOK, this should fix the rest of the broken tests.
Comment #46
phenaproximaThe good news: this will almost certainly fix the tests, and clear the way for us to implement the todos added in #42.
The bad news: I had to do a not-insignificant amount of clean-up and refactoring in MediaLibraryTest to make it only use functional selectors, rather than the ones that are coming from Classy/Seven. The upshot is that this not only makes the test a little easier to understand, but should also help make it easier to run the tests against both Classy and Seven later on. Unfortunately, that necessitated a lot of small changes which increased the size of this patch to well over 100 KB. 🤪
Comment #47
phenaproximaAnother "self-review", with notes to help the next set of eyes make sense of my changes.
This is a preemptive bug fix. If the structure of the field widget is changed (e.g., by a template), the weight toggling can fail, which is a critical accessibility problem.
The with-input and without-input classes were being used by tests, but they are now added by the theme and were never functional in nature anyway. Although this is purely for testing, switching to a data attribute gets around that. (Ideally we would just remove these assertions from MediaLibraryTest, to be honest, but I thought it was better not to remove coverage.)
We can no longer rely on these presentational classes.
.media-library-item__remove is a presentational theme class that has no js- prefixed equivalent (and does not need one), so a fair number of the changes to MediaLibraryTest are about accessing the "Remove" button in a CSS-agnostic way.
This can be deleted, it's cruft from refactoring.
I moved the waitForText() call into openMediaLibraryForField(). In core, there is no
circumstance under which that text will fail to appear if the media library has opened successfully. I thought this was a nice way to increase the test's assertiveness while decreasing its verbosity.
.media-library-wrapper is presentational and added by the theme now. #media-library-wrapper, on the other hand, is functional and used as an AJAX target.
getTypesMenu() was added to abstract away the CSS selector used to get to the menu (it was previously a presentational class).
This pattern ($assert_session->elementExists()->pressButton(), followed by the waiting for an announcement) was repeated all over the place. I made it its own method for clarity and reduced verbosity.
This is important accessibility test coverage and definitely should not rely on presentational CSS selectors.
.media-library-item is presentational. [data-media-library-item-delta] is functional and added by the widget for accessibility reasons. :)
This removes the reliance on presentational classes, and increases the precision of the assertions/interactions.
Again, .media-library-selected-count was repeated all over the place. There was no need for that, so I removed it.
The "added media" area has a lot of presentational classes in it. To abstract those away, I created assertMediaAdded() and assertNoMediaAdded().
Same idea here -- getSelectionArea() is abstracting a presentational selector away.
assertMediaAdded() asserts that the media types menu doesn't appear. When new media is being added, it never should. So this increases the assertiveness and "correctness" of the test.
Again, the idea here was to remove the reliance on CSS selectors in favor of functional markup.
Whoops, typo.
Comment #48
phenaproximaI paired with @lauriii on this for a couple of hours today. We were able to make a lot of headway. I'm most proud of turning the list of added media generated by AddFormBase into a true item list -- that's more semantically correct and certainly more themeable.
Changes to MediaLibraryWidget continue to be challenging. The problem is that the AJAX operations (like removing things, updating the widget, and so forth) tend to be very sensitive to the relative positions of various elements in the render array, so anything which reorganizes the render array for theming purposes tends to compromise it.
Therefore, some things are more themeable now; other things will continue to be in hook_form_alter() and preprocess functions. Exactly which mechanisms we use, and were, are decisions @lauriii needs to make one by one.
@lauriii has promised to review this patch tomorrow (his time), ignoring the changes to MediaLibraryTest (which are not functional changes; just making it less sensitive to particular selectors). I ran MediaLibraryTest locally and it passes handily for me.
Comment #49
phenaproximaAnd, hey! I was able to do a thing @lauriii had asked for, which was create a new media_library_item template for use in both the widget, to display selected items, and in the "Additional selected media" area in the advanced UI. Mission accomplished!
This passed tests locally.
Comment #50
phenaproximaThis is out of date and needs to be removed. :)
Comment #51
phenaproximaA little more work here...I removed the outdated comment, and also found a way to make the "Add media" button in the widget more theme-friendly. By moving it into the fieldset's suffix with a #pre_render callback, I was able to remove another preprocess function. If we add a preprocess function in media_library.module, we could potentially expose it in the template as its own variable, which would be cool. I think things are shaping up!
This passed tests locally, too. 🤞
Comment #52
lauriiiI did some further research and something we haven't really discussed is what should we do with the fact that some of the representational classes are hardcoded in the Views configurations. How should themes be able to style those elements? 🤔
Example 1: I'm providing support for Media Library in a theme built with Bootstrap and I want to replace the
media-library-itemwithcardclass.Example 2: I'm implementing Media Library designs in Claro and I want to use our pre-existing
action-linkcomponent for the edit link. I want to replacemedia-library-item__editwithaction-link action-link--icon-pencil.Comment #53
lauriiiDid some research on the Views stuff and it will be huge PITA to have these classes set in the Views configurations since every time we want to change the markup, we will have to make an update hook for that. We could use something like
hook_views_pre_renderto add the classes in a theme instead. This way the classes could be updated on fly without update hooks.Example:
I'm wondering what should we do with the existing classes if we did this? Maybe we could just leave them intact in existing installations and remove them from the default configuration? We could recommend users who care about this to reinstall Media Library.
I must admit that I'm not a Views expert so there might be better approaches for this. Anyone thoughts?
Comment #54
phenaproxima+1 for this approach. Update paths are a complex and potentially dangerous pain in the ass, especially where Views is concerned, and we already have too many of them in Media Library. For existing sites, AFAICT the worst case scenario of the proposed approach is that they'll have a few additional, harmlessly inert classes scattered around, which they can easily remove in Views UI (or uninstall/reinstall, as you say).
Comment #55
effulgentsia commentedNice approach! But we need to append to rather than overwrite the existing link_class. We probably also want to make the append logic smart enough to prevent duplicates.
I don't think that should be the deciding factor. But, I do think that a good argument for not removing these classes from people's existing ML View is to preserve BC for a site that has a custom theme that's already styling these classes.
I don't think that this is the best recommendation, because doing so has other side effects. For example, if you install ML, and then add Media fields to content types, they default to the ML widget. If you then uninstall and reinstall ML, all those widgets become generic autocomplete ER widgets instead. But, I think we can recommend that for someone who wants to reset their ML View to the one provided by the ML codebase, that they can use
/admin/config/development/configuration/single/importto do that and just paste in the YML frommedia_library/config/install/views.view.media_library.yml. Let's include that in the eventual CR that's written for this.Comment #56
phenaproximaI paired with @lauriii again and we went through the view, moving classes into either
media_library_views_pre_render()orseven_views_pre_render()as appropriate. This necessitated another big round of changes to MediaLibraryTest, which is now refactored quite a bit, to be honest, but I think it still has the same coverage as before, and with increased assertiveness and flexibility.This passed all tests locally except for \Drupal\Tests\media_library\FunctionalJavascript\MediaLibraryTest::testAdministrationPage(), but that frequently has random failures on my machine, and I don't think we did anything that will break it on testbot. But, we'll see.
No interdiff because, as with many iterations of this patch, it would be unjustifiably large and confusing.
Comment #58
phenaproximaSome things from my walk-through with @effulgentsia:
This isn't bueno. The media_library_item template should be a theme wrapper in order to avoid this.
This should be using a render element in its theme hook, rather than two property/render arrays.
Let's add a new class extending MediaLibraryTest, which runs all of the same tests in the Seven theme (and includes this assertion). That way we can have our Classy cake and eat Seven too.
Can this be moved into seven_views_pre_render()? And more to the point, should we?
Comment #59
phenaproximaThis should fix those dastardly test failures.
Comment #60
phenaproximaMade the changes @effulgenstia requested (#1-3) in #58. This passed tests locally!
Comment #61
phenaproxima@lauriii did a walkthrough of this patch, looking at every presentational class and determining where each is added, and by what. He even made a beautiful spreadsheet with his findings! 😍 🙏
This latest patch fixes the last bits of feedback from that round of review:
Comment #62
phenaproximaTo make it easier to commit this monstrous patch, @effulgentsia asked me to move the JavaScript bugfixes, and as many changes to MediaLibraryTest as possible, to another issue. So I opened #3088681: Make MediaLibraryTest less dependent on representational CSS selectors for that -- once we commit it and reroll this, we should shave a good 85 KB off this patch. Which this patch could sorely use.
Comment #63
lauriiiThis is supposed to be used for render element rendered hook_theme functions only. We are not rendering these using render elements meaning we should use variables instead. 🦖
Let's add
@see media_library_preprocess_media()here 📄Maybe out of scope but let's at least file a follow-up. We should check if
preview_attributesormetadata_attributeshave been set before. 🔬👁These docs need updating. We should also replace the current reference to preprocess function with
@see template_preprocess_media_library_item()📄Also the template in Seven should be updated with
Let's add
@see template_preprocess_media_library_wrapper()📄Can we open follow-up for this? 💼
Docs need updating 📄
It seems unnecessary to create a local variable for adding a single class. 🚣♂️
Let's add
@see classy_preprocess_links__media_library_menu()here. 📄Let's add
@see seven_preprocess_fieldset__media_library_widget()here 📄Let's add
@see seven_preprocess_item_list__media_library_add_form_media_list()here 📄Comment #64
phenaproximaRerolled on top of #3088681: Make MediaLibraryTest less dependent on representational CSS selectors. I haven't yet addressed @lauriii's feedback; I wanted to get that damn reroll out of the way. Phew!
Comment #65
phenaproximaAddressing #63:
Also fixing a dumb mistake in #64 which will cause tests to fail.
Comment #67
effulgentsia commentedRe #65.1, right, here's more places related to that...
Render arrays should not be assigned to #properties, so this change moves in the wrong direction.
These can be #theme rather than #theme_wrappers. Because the media library item is its own render element that doesn't have or need a separate #theme function other than this one.
Converting media_library_item from a #theme_wrapper to a #theme would allow these assignments of a render array to a #property to be removed.
Comment #68
phenaproximaI like those suggestions! This patch implements them. It allowed me to remove a couple of pre-renders, as promised, and also revert changes to MediaLibraryAddFormTest, which is good. I think this reduces complexity and increases flexibility, so I'm all for it! Plus, it slims down the size of the patch :)
Comment #69
effulgentsia commentedLooks like this didn't make it into #3088681: Make MediaLibraryTest less dependent on representational CSS selectors. Can we open a new issue for it?
Comment #70
effulgentsia commentedSame for this. Can be part of the same issue as #69.
Comment #71
effulgentsia commentedSame for this. Can also be part of the same issue as #69.
Comment #72
effulgentsia commentedWhy are we removing this test coverage?
Is this related to this issue? If so, how?
Comment #73
effulgentsia commentedThese are pretty involved templates, and we're only overriding the default in a trivial way (adding a class or two). I think for these, it would be better to follow a pattern of using
extends. E.g.,Note that I'm aware that there's feedback in #2387069-104: {% extends "foo.html.twig" %} in Twig templates does not respect theme inheritance to not do stuff like that, but there hasn't yet been an agreed upon resolution to that, and in the meantime, core already does it in places like
field--text.html.twig, and IMO, that's better than duplicating and maintaining duplicates of non-trivial Twig code and markup.Comment #74
effulgentsia commentedWe don't have a copy of this in Stable. Should we? And if so, should we copy this one, or the one prior to these changes?
Do we need to add copies of these in Stable as well?
Comment #75
effulgentsia commentedBecause these are containers, should we also add the
has_parent ? ['js-form-wrapper', 'form-wrapper']classes too, for consistency with Classy'scontainer.html.twig?Comment #76
effulgentsia commentedNW for addressing #69 - #75, whether that means fixing the patch, or commenting as to why the feedback is incorrect.
Comment #77
phenaproximaSelf-assigning to deal with all that.
Comment #78
phenaproximaAddressing #72:
Addressing #73:
I was able to change this in two of the templates. The two I couldn't change --
fieldset--media-library-widget.html.twigandmedia--media-library.html.twig-- are hard-coding new classes into the markup, not just using local variables to add classes, so I don't think they can extend a base template.Addressing #74:
I'm leaving these as-is for now.
Addressing #75:
I decided to leave these as-is for now.
has_parentisn't really super relevant to theming these things; we're usingcontainerfor convenience here, because we need a DIV, with attributes, wrapping other elements. Because of where they're being used, these specific templates will always have a parent, so anyhas_parentstuff is probably just a confusing and borderline-useless appendage in this case.That said, I don't feel very strongly about this, so I'm fine with restoring
has_parentand its related classes if wanted.Comment #79
phenaproximaOpened #3089168: Remove or reduce representational CSS classes in all Media Library tests to deal with #69 through #71.
Comment #80
lauriii#74.1 & 2 Adding templates to Stable should be done as part of the stable maker patch. 👍
Comment #82
phenaproximaWhoops, sorry! Accidentally removed some stuff from MediaLibraryTest::testFieldUiIntegration() that should still be there.
Comment #83
phenaproximaRerolled on top of the changes in #3089168-7: Remove or reduce representational CSS classes in all Media Library tests, shaving another 20 KB off the size of the patch. Yeah!
Comment #84
phenaproximaDiscussed #75 with @effulgentsia. We agreed that our specialized
containertemplates should probably not deviate too much from the default template for containers, so kicking this back to "needs work" to restore thehas_parentflag, and related classes, to those templates.Also waiting on #3089168: Remove or reduce representational CSS classes in all Media Library tests to reduce noise in this issue.
Comment #85
phenaproximaMission not accomplished! 😛
Comment #86
phenaproximaOK, I had to reroll again due to #3085908: Media library thumbnails are blurry/skewed in IE11 causing a pile of merge conflicts. 🤪
But, this is it. I don't think we'll need any more rerolls -- just iterations (and hopefully few of those, at that). This also fixes the stuff in #75, as @effulgentsia and I agreed on in #84.
Comment #87
phenaproximaLooks like there's a bunch of weird patch noise in #86. I can't explain what's going on; I originally got it due to PHPStorm "intelligently" reformatting my code during paste (eurgh), but I thought I'd removed it all.
Trying again...
Comment #88
phenaproximaI have now written four change records, which I think covers the complete scope of this issue. That has to be some sort of record. Removing the tag. :)
Comment #89
phenaproximaAlso... @lauriii and I did a substantial amount of pair programming on this patch. He has guided and approved the approach we took at every step of the way. He did a detailed patch read-through as we approached the final form, and he reviewed and validated @effulgentsia's feedback and suggestions in Slack. I have exactly zero reasons to believe he has any problem with what we've wrought here.
In light of all this, I'm removing the "needs frontend framework manager review" tag.
Comment #90
phenaproximaCrediting @lauriii and @effulgentsia for guidance, pairing, and reviews.
Comment #91
phenaproximaI think it's time I un-assigned this.
Comment #92
effulgentsia commentedI think my only remaining concern with this patch is that a bunch of CSS class assignments are moved to Seven, but remain part of selectors in
media_library.modules.cssandmedia_library.theme.css. One example is themedia-library-viewclass, but there are also a few others.I'm RTBCing this, because I think it's ok to commit this as a great step, but I don't think we should mark Media Library as stable until we bring consistency to that (either by moving those classes to Classy, or else moving the CSS rules to Seven).
Comment #93
phenaproximaThis is actually addressed in the stable-maker; that patch includes sections that move virtually all of the CSS to Seven. @lauriii and I discovered that the media library works fine in Stark, and most of the styling that is currently in Media Library (both in the
theme.cssandmodule.cssfiles) is geared towards Seven.So, tl;dr: we don't need a new issue or anything for this; we will sort out the correct locations for the CSS in the same commit that marks Media Library stable. :)
Comment #94
phenaproximaLinking the "stable maker" I keep talking about, so that future readers of this issue will be able to find it.
Comment #95
lauriii.media-library-view--widget .media-library-select-allwill break on Stark and Stable as a result of this patch. Could this be replaced with avisually-hiddenclass for example?The classes variable is not being used at the moment at all. 🔬👁
This might be something to a follow-up since this isn't caused by this issue but this causes a usability problem because the name field cannot be adjusted in the Field UI. There's an issue to resolve a similar problem in other entity types: #2353867: [META] Expose Title and other base fields in Manage Display.
Comment #96
phenaproximaI don't think so, because
visually-hiddenwill still keep it accessible to screen readers. We want to suppress it entirely, which is why it usesdisplay: none, IIRC.My suggestion would be, instead, to change the selector take advantage of the default classes Views adds to a view. So something like:
.view-media-library.view-display-id-page .media-library-select-all. That's not perfect, but it might be good enough for now, and in theory we could change it later since the select box is added squarely by module-provided JavaScript, and suppressed by module-provided CSS. This is, for sure, the quickest and easiest option for us to do in this patch.Another option is for us to change that JavaScript so that it only adds the checkbox to
.js-media-library-view.view-display-id-page: a combination of the default classes Views adds, and our own functional class. That would also be an internal module-level change.Yet another option would be for media_library_views_pre_render() to add a
js-no-select-allclass to the widget displays inmedia_library_views_pre_render(), then adjust the JS to recognize that. This, too, would be an internal module-level change.Do you have a preference?
I'm not sure what "this" is referring to here?
Comment #97
lauriiiThis seems like a good solution to this 👍
I was suggesting not to make a commit in this issue but instead, add these changes to be part of the stable maker issue.
Comment #98
phenaproximaAddressing #95:
.js-media-library-view.view-display-id-page. This allowed me to remove the CSS rule entirely, and remove MediaLibrarySevenTest::openMediaLibraryForField(). Hooray for better tests!Comment #99
phenaproximaOpened #3089416: Media name should not be hardcoded in templates to address #95.4.
Comment #100
lauriiiThis is not a reliable way to determine the display id because this is only added in Classy.
Comment #101
lauriiiDiscussed with @phenaproxima about how to recognize the View ID reliably and we agreed that we would use
hook_preprocess_views_viewin the Media Library module to add a new data attribute for the View ID.Comment #102
phenaproximaAlmost. 😛 It's the display ID I need, not the view ID. So I'll add this data attribute to the
media_libraryview only, and it will contain the display ID for targeting.Comment #103
lauriiiSounds good 😅
Comment #104
phenaproximaOkay! This addresses #100.
Comment #105
phenaproximaForgot to run
yarn prettieron the previous patch. 🙄Comment #106
bnjmnmLooks like all the feedback is properly addressed and it's been scrutinized by Drupal's finest, so RTBC.
Comment #107
lauriiiAll my feedback has been addressed. Let’s move the patch to the stable maker issue.
Comment #108
lauriiiI just noticed that the grep I did yesterday excluded the
.modulefile because I only grepped *.php and *.es6.js files 😭I run the grep against media_library.module and found out that there are two more classes that should be moved frommedia_library_preprocess_views_view_fieldsand_media_library_views_form_media_library_after_buildto themes.Comment #109
phenaproximaThis patch fixes #108 thusly:
media-library-item__click-to-select-triggerclass frommedia_library_preprocess_views_view_fields(). The previous patch already moved it toseven_preprocess_views_view_fields__media_library().media_library_form_alter(), to Seven.Comment #110
lauriiiLooks good! Feel free to mark this as fixed once this has been added to the stable maker.
Comment #112
phenaproximaThe failing tests reveal a problem: the stuff I moved out of media_library_form_alter() is actually functional, not presentational, in nature. The #after_build function is responsible for ensuring that the "Apply filters" button is not moved into the modal dialog's button area. So that must live in the Media Library module.
It will be a little verbose for sure, but I'll try to have it both ways -- keep the button where it is, but move the CSS class into Seven. I think it should be doable.
Comment #113
phenaproximaOK. This should fix the tests. I was able to have my cake and eat it too; the stuff that keeps the "Apply filters" button out of the modal dialog's button area is in the Media Library module, as it should be. And the code that adds the
media-library-view-form--actionsclass is in Seven, as it should be.Comment #115
phenaproximaWell, okay. This oughta do the trick.
Comment #116
phenaproximaImproving and expanding a comment for accuracy, per @lauriii's request.
Comment #117
phenaproximaOh, and: moved all of the Media Library templates to Seven's templates directory. 😅No interdiff because literally all I did was move some files around.
Comment #118
phenaproximaRerolled following the revert of #3085908: Media library thumbnails are blurry/skewed in IE11.
Comment #119
lauriiiLooks good. All the feedback has been addressed and tests are passing for #117. Feel free to mark this as fixed after adding this to the stable maker.
Comment #120
phenaproxima#3082690-62: Mark Media Library as a stable core module already includes #118, so that's done. Marking fixed. Thanks!