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\MediaLibraryWidget and media--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

CommentFileSizeAuthor
#118 3087456-118.patch79.51 KBphenaproxima
#117 3087456-117.patch79.51 KBphenaproxima
#116 interdiff-3087456-115-116.txt1.23 KBphenaproxima
#116 3087456-116.patch79.42 KBphenaproxima
#115 interdiff-3087456-113-115.txt1.79 KBphenaproxima
#115 3087456-115.patch78.95 KBphenaproxima
#113 interdiff-3087456-109-113.txt3.36 KBphenaproxima
#113 3087456-113.patch79.52 KBphenaproxima
#109 interdiff-3087456-105-109.txt3.79 KBphenaproxima
#109 3087456-109.patch79.79 KBphenaproxima
#105 interdiff-3087456-104-105.txt785 bytesphenaproxima
#105 3087456-105.patch77.17 KBphenaproxima
#104 interdiff-3087456-98-104.txt3.27 KBphenaproxima
#104 3087456-104.patch77.03 KBphenaproxima
#98 interdiff-3087456-87-98.txt5 KBphenaproxima
#98 3087456-98.patch75.66 KBphenaproxima
#87 3087456-87.patch73.94 KBphenaproxima
#86 3087456-86.patch73.94 KBphenaproxima
#83 3087456-83-reroll-on-3089168_7-do-not-test.patch73.55 KBphenaproxima
#82 interdiff-3087456-78-82.txt1.15 KBphenaproxima
#82 3087456-82.patch95.91 KBphenaproxima
#78 interdiff-3087456-68-78.txt4.74 KBphenaproxima
#78 3087456-78.patch95.6 KBphenaproxima
#68 interdiff-3087456-65-68.txt11.71 KBphenaproxima
#68 3087456-68.patch96.56 KBphenaproxima
#65 interdiff-3087456-64-65.txt16.86 KBphenaproxima
#65 3087456-65.patch101.21 KBphenaproxima
#64 3087456-64.patch100.46 KBphenaproxima
#61 interdiff-3087456-60-61.txt11.15 KBphenaproxima
#61 3087456-61.patch170.01 KBphenaproxima
#60 interdiff-3087456-59-60.txt7.59 KBphenaproxima
#60 3087456-60.patch169.96 KBphenaproxima
#59 interdiff-3087456-56-59.txt1.29 KBphenaproxima
#59 3087456-59.patch168.32 KBphenaproxima
#56 3087456-56.patch166.77 KBphenaproxima
#51 interdiff-3087456-49-51.txt4.79 KBphenaproxima
#51 3087456-51.patch141.5 KBphenaproxima
#49 3087456-49.patch140.17 KBphenaproxima
#48 3087456-48.patch127.78 KBphenaproxima
#46 3087456-46.patch115.33 KBphenaproxima
#44 3087456-44.patch77.8 KBphenaproxima
#42 3087456-42.patch60.99 KBphenaproxima
#36 3087456-36.patch37.78 KBphenaproxima
#35 3087456-35.patch38.61 KBphenaproxima
#34 interdiff-3087456-32-34.txt2.1 KBphenaproxima
#34 3087456-34.patch37.48 KBphenaproxima
#32 interdiff-3087456-27-32.txt4.21 KBphenaproxima
#32 3087456-32.patch35.22 KBphenaproxima
#27 interdiff-3087456-25-27.txt1.91 KBphenaproxima
#27 3087456-27.patch33.89 KBphenaproxima
#25 interdiff-3087456-18-25.txt4.5 KBphenaproxima
#25 3087456-25.patch32.3 KBphenaproxima
#18 interdiff-3087456-17-18.txt3.13 KBphenaproxima
#18 3087456-18.patch30.32 KBphenaproxima
#17 interdiff-3087456-15-17.txt11.3 KBphenaproxima
#17 3087456-17.patch30.66 KBphenaproxima
#16 ugly-bug.png408.37 KBphenaproxima
#15 interdiff-3087456-14-15.txt8.3 KBphenaproxima
#15 3087456-15.patch30.75 KBphenaproxima
#14 3087456-14.patch32.82 KBoknate
#14 3087456--interdiff-12-14.txt4.54 KBoknate
#12 3087456-12.patch31.58 KBphenaproxima
#10 3087456-10.patch26.46 KBphenaproxima
#7 3087456-7.patch37.37 KBphenaproxima
#6 3087456-6.patch29.24 KBphenaproxima
#5 3087456-5.patch17.73 KBphenaproxima
#3 3087456-3.patch11.01 KBphenaproxima

Comments

lauriii created an issue. See original summary.

lauriii’s picture

This opens a big can or worms. There's a lot of classes being added in media_library_preprocess_media, Drupal\media_library\Form\AddFormBase, and Drupal\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.

phenaproxima’s picture

Status: Active » Needs review
StatusFileSize
new11.01 KB

This should fix all instances of '#type' => 'container' in AddFormBase.

lauriii’s picture

+++ b/core/modules/media_library/src/Form/AddFormBase.php
@@ -286,21 +286,17 @@ protected function buildEntityFormElement(MediaInterface $media, array $form, Fo
+        '#theme_wrappers' => [
+          'container__media_library_add_form__fields',
         ],

container__media_library_add_form__fields will create two different suggestions: container__media_library_add_form and container__media_library_add_form__fields. I don't think anyone would ever use the container__media_library_add_form suggestion because these are completely independent elements.

phenaproxima’s picture

StatusFileSize
new17.73 KB

Oops! 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.

phenaproxima’s picture

StatusFileSize
new29.24 KB

Addressed 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.

phenaproxima’s picture

StatusFileSize
new37.37 KB

Fixed every input element, container, and HTML tag in MediaLibraryWiget.

The last submitted patch, 6: 3087456-6.patch, failed testing. View results

Status: Needs review » Needs work

The last submitted patch, 7: 3087456-7.patch, failed testing. View results

phenaproxima’s picture

Status: Needs work » Needs review
StatusFileSize
new26.46 KB

OK -- 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.

Status: Needs review » Needs work

The last submitted patch, 10: 3087456-10.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

phenaproxima’s picture

Status: Needs work » Needs review
StatusFileSize
new31.58 KB

I 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.

phenaproxima’s picture

Status: Needs review » Needs work

Here's a little self-review, and a "guide" of sorts to this patch for the next person who looks at it.

  1. +++ b/core/modules/media_library/media_library.module
    @@ -144,9 +144,7 @@ function media_library_preprocess_media(&$variables) {
    -    $variables['metadata_attributes'] = new Attribute();
    

    I shouldn't have moved this line into Classy. It needs to be moved back.

  2. +++ b/core/modules/media_library/src/Form/AddFormBase.php
    @@ -157,23 +157,24 @@ public function buildForm(array $form, FormStateInterface $form_state) {
    +            // This needs to be focus-able by an AJAX response.
    +            // @see ::updateFormCallback()
    +            'js-media-library-add-form__added-media',
    

    This is new class, but updateFormCallback() was previously targeting the representational one.

  3. +++ b/core/modules/media_library/src/Form/AddFormBase.php
    @@ -187,14 +188,11 @@ public function buildForm(array $form, FormStateInterface $form_state) {
    +        '#type' => 'container',
    +        '#theme_wrappers' => [
    +          'container__media_library_add_form_description',
             ],
    +        'description' => $this->formatPlural(count($added_media), 'The media item has been created but has not yet been saved. Fill in any required fields and save to add it to the media library.', 'The media items have been created but have not yet been saved. Fill in any required fields and save to add them to the media library.'),
    

    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.

  4. +++ b/core/modules/media_library/src/Form/AddFormBase.php
    @@ -628,13 +627,13 @@ public function updateFormCallback(array &$form, FormStateInterface $form_state)
    -        $response->addCommand(new InvokeCommand(".media-library-add-form__media[data-media-library-added-delta=$delta_to_focus]", 'focus'));
    +        $response->addCommand(new InvokeCommand("[data-media-library-added-delta=$delta_to_focus]", 'focus'));
    

    The .media-library-add-form__media part of the modified selector was redundant anyway. Nothing else gets the data-media-library-added-delta attribute.

  5. +++ b/core/modules/media_library/src/Form/FileUploadForm.php
    @@ -106,6 +106,15 @@ public static function create(ContainerInterface $container) {
    +  /**
    +   * {@inheritdoc}
    +   */
    +  public function buildForm(array $form, FormStateInterface $form_state) {
    +    $form = parent::buildForm($form, $form_state);
    +    $form['#theme_wrappers'] = ['form__media_library_add_form_upload'];
    +    return $form;
    +  }
    

    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 :)

  6. +++ b/core/modules/media_library/src/Plugin/Field/FieldWidget/MediaLibraryWidget.php
    @@ -338,25 +340,23 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen
    +        '#type' => 'container',
    +        '#theme_wrappers' => [
    +          'container__media_library_widget_empty_text',
             ],
    +        'text' => $this->t('No media items are selected.'),
    

    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.

  7. +++ b/core/modules/media_library/src/Plugin/Field/FieldWidget/MediaLibraryWidget.php
    @@ -338,25 +340,23 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen
    +        '#type' => 'button',
    +        '#theme_wrappers' => [
    +          'input__submit__media_library_widget_toggle_weight',
    +        ],
    

    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...

  8. +++ b/core/modules/media_library/src/Plugin/views/field/MediaLibrarySelectForm.php
    @@ -47,9 +47,7 @@ public function render(ResultRow $values) {
    -    $form['#attributes'] = [
    -      'class' => ['media-library-views-form', 'js-media-library-views-form'],
    -    ];
    +    $form['#attributes']['class'] = ['js-media-library-views-form'];
    

    In manual testing, I established that the media-library-views-form class is being applied by Classy. So it's not needed here. :)

  9. +++ b/core/modules/media_library/src/Plugin/views/field/MediaLibrarySelectForm.php
    @@ -107,10 +105,7 @@ public function viewsForm(array &$form, FormStateInterface $form_state) {
    -    $form['actions']['submit']['#attributes'] = [
    -      'class' => ['media-library-select'],
    -      'data-disable-refocus' => 'true',
    -    ];
    +    $form['actions']['submit']['#attributes']['data-disable-refocus'] = 'true';
    

    Same thing here.

oknate’s picture

StatusFileSize
new4.54 KB
new32.82 KB

Addressing #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 .👍

phenaproxima’s picture

StatusFileSize
new30.75 KB
new8.3 KB

Thanks, @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.

phenaproxima’s picture

StatusFileSize
new408.37 KB

One 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.

An ugly bug when adding new media in the modal

phenaproxima’s picture

Status: Needs work » Needs review
StatusFileSize
new30.66 KB
new11.3 KB

This patch fixes the ugly bug (turned out to be me using #theme where 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.

phenaproxima’s picture

StatusFileSize
new30.32 KB
new3.13 KB

Managed to remove a couple more #theme_[wrappers] overrides in FileUploadForm and OEmbedForm.

phenaproxima’s picture

Here's a little brain dump, primarily directed at @lauriii, about the current state of this patch.

  • I expect #18 to pass tests. If it does, that's frankly amazing: less work for us! 🥳
  • I personally am a big fan of using hook_form_alter to allow Classy to influence AddFormBase. Although @lauriii tells me it is "discouraged", it is in my opinion the cleanest and most straightforward option for overriding the add form's markup/styling, by far. Adding pseudo-templates everywhere (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.
  • From my perspective, the problem with hook_form_alter is that doing it properly necessitates adding BaseFormIdInterface to AddFormBase. Well, it doesn't exactly necessitate it...but if we don't do that, then anything wanting to alter the add forms we ship in core (FileUploadForm and OEmbedForm) will need to alter the same form ID, and detect which class is being used to generate the form ($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.
  • The hardest parts of Media Library to "frontend-ize" are the field widget, and the output of MediaLibraryUiBuilder. The field widget is tough because themes cannot implement hook_field_widget_form_alter() -- if they could, we'd just do a similar thing as with AddFormBase, and be done with it. As it is, we can get by with pseudo-theme hooks (as implemented in #18). I'm really not too keen on the idea of the widget having a template of its own; that seems complex and heavy, in exchange for little gain and increased fragility.
  • As far as MediaLibraryUiBuilder goes, I'm debating whether it would be worthwhile for us to add a new theme hook/template for that (called media_library in code, and media-library.html.twig in 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.
  • If we don't want to move some of the more questionable things in #18 -- like the form_alter hooks -- into Classy, @lauriii proposed potentially moving them into Seven for the purposes of getting Media Library stable. I'm fine with that; the main goal here is to get all styling-related CSS classes out of Media Library, and into a theme; I don't much care which theme it is. :) Seven is a fine place to put them for now, to be honest, because all of our current styling is targeted for Seven anyway, and that's where it will be moved when we mark the module stable.
oknate’s picture

Another 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?"

function classy_preprocess_input__submit__media_library_widget_toggle_weight(array &$variables) {
 unset($variables[‘attributes’][‘name’]);
}

phenaproxima:

Because of the markup we need: <button>STUFF</button>. There is no template which provides that.
oknate’s picture

Regarding this:

I personally am a big fan of using hook_form_alter to allow Classy to influence AddFormBase. Although @lauriii tells me it is "discouraged",

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?

oknate’s picture

I 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.

oknate’s picture

Title: Add media--media-library.html.twig to Classy » Move representational classes in Media Library to Classy
Issue summary: View changes

Issue summary update to encompass the larger scope other than the one file.

oknate’s picture

Issue summary: View changes
phenaproxima’s picture

StatusFileSize
new32.3 KB
new4.5 KB

Found a way to remove the awkward input__submit__media_library_toggle_weight pseudo-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:

  1. These are sane defaults. The empty text is markup-free, and the weight toggle is a <button> element -- which, IIRC, it needs to be for accessibility reasons -- so, in the absence of a <button>STUFF</button> template, I would argue that this is a legitimate, functional use of '#type' => 'html_tag'.
  2. They can still be modified or replaced in a preprocess function, as is now demonstrated by classy_preprocess_fieldset__media_library_widget().

The only reason I have a new fieldset--media-library-widget.html.twig template 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.

Status: Needs review » Needs work

The last submitted patch, 25: 3087456-25.patch, failed testing. View results

phenaproxima’s picture

Status: Needs work » Needs review
StatusFileSize
new33.89 KB
new1.91 KB

Nice job, MediaLibraryTest! #25 caught a legitimate problem -- Drupal.behaviors.MediaLibraryWidgetToggleWeight is not tolerant of the surrounding markup being changed. Should be fixed in this patch.

phenaproxima’s picture

Tagging for front-end framework manager review.

phenaproxima’s picture

Something 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.

seanb’s picture

I’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 😞

phenaproxima’s picture

You'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?

phenaproxima’s picture

StatusFileSize
new35.22 KB
new4.21 KB

I 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).

Status: Needs review » Needs work

The last submitted patch, 32: 3087456-32.patch, failed testing. View results

phenaproxima’s picture

Status: Needs work » Needs review
StatusFileSize
new37.48 KB
new2.1 KB

This will fix the tests.

phenaproxima’s picture

StatusFileSize
new38.61 KB

Moved 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.)

phenaproxima’s picture

StatusFileSize
new37.78 KB

Whoops! Sorry, #35 accidentally included an unrelated change.

lauriii’s picture

I 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.

Status: Needs review » Needs work

The last submitted patch, 36: 3087456-36.patch, failed testing. View results

xjm’s picture

Priority: Normal » Major
Issue tags: +Contributed project soft blocker

This issue is a potential contrib blocker for making it easy for themes to support Media Library.

effulgentsia’s picture

Title: Move representational classes in Media Library to Classy » Move some representational classes in Media Library to Classy and others to Seven and/or Claro, as appropriate
effulgentsia’s picture

Perhaps a good next step here is to propose which CSS class additions belong in Seven and do not belong in Classy, and why?

phenaproxima’s picture

Status: Needs work » Needs review
StatusFileSize
new60.99 KB

Lucky 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.

Status: Needs review » Needs work

The last submitted patch, 42: 3087456-42.patch, failed testing. View results

phenaproxima’s picture

Status: Needs work » Needs review
StatusFileSize
new77.8 KB

OK, this should fix the rest of the broken tests.

Status: Needs review » Needs work

The last submitted patch, 44: 3087456-44.patch, failed testing. View results

phenaproxima’s picture

Status: Needs work » Needs review
StatusFileSize
new115.33 KB

The 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. 🤪

phenaproxima’s picture

Another "self-review", with notes to help the next set of eyes make sense of my changes.

  1. +++ b/core/modules/media_library/js/media_library.widget.es6.js
    @@ -58,7 +58,7 @@
    -            .parent()
    +            .closest('.js-media-library-widget')
    

    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.

  2. +++ b/core/modules/media_library/src/Form/AddFormBase.php
    @@ -157,23 +158,25 @@ public function buildForm(array $form, FormStateInterface $form_state) {
    -      $form['#attributes']['class'][] = 'media-library-add-form--with-input';
    -
    +      $form['#attributes']['data-input'] = 'true';
    

    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.)

  3. +++ b/core/modules/media_library/tests/src/FunctionalJavascript/CKEditorIntegrationTest.php
    @@ -222,7 +222,7 @@ public function testButton() {
    -    $assert_session->elementExists('css', 'button.media-library-select.button.button--primary')->click();
    +    $assert_session->elementExists('css', '.ui-dialog-buttonpane')->pressButton('Insert selected');
    

    We can no longer rely on these presentational classes.

  4. +++ b/core/modules/media_library/tests/src/FunctionalJavascript/EmbeddedFormWidgetTest.php
    @@ -122,8 +122,8 @@ public function testInsertionAndReselection($widget) {
    -    $this->assertTrue($assert_session->waitForElementVisible('xpath', $first_item_locator));
    -    $assert_session->elementExists('css', '.media-library-item__remove')->click();
    +    $this->assertTrue($first_item = $assert_session->waitForElementVisible('xpath', $first_item_locator));
    +    $first_item->pressButton('Remove');
    

    .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.

  5. +++ b/core/modules/media_library/tests/src/FunctionalJavascript/MediaLibraryTest.php
    @@ -2,6 +2,7 @@
    +use Behat\Mink\Element\NodeElement;
    

    This can be deleted, it's cruft from refactoring.

  6. +++ b/core/modules/media_library/tests/src/FunctionalJavascript/MediaLibraryTest.php
    @@ -439,7 +440,6 @@ public function testWidget() {
         $this->openMediaLibraryForField('field_unlimited_media');
    -    $this->waitForText('Add or select media');
    

    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.

  7. +++ b/core/modules/media_library/tests/src/FunctionalJavascript/MediaLibraryTest.php
    @@ -479,7 +479,7 @@ public function testWidget() {
    -    $this->openMediaLibraryForField('field_single_media_type', '.media-library-wrapper');
    +    $this->openMediaLibraryForField('field_single_media_type', '#media-library-wrapper');
    

    .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.

  8. +++ b/core/modules/media_library/tests/src/FunctionalJavascript/MediaLibraryTest.php
    @@ -494,7 +494,7 @@ public function testWidget() {
    +    $links = $this->getTypesMenu()->findAll('css', 'a');
    

    getTypesMenu() was added to abstract away the CSS selector used to get to the menu (it was previously a presentational class).

  9. +++ b/core/modules/media_library/tests/src/FunctionalJavascript/MediaLibraryTest.php
    @@ -560,50 +560,55 @@ public function testWidget() {
    -    $assert_session->elementExists('css', '.ui-dialog-buttonpane')->pressButton('Insert selected');
    -    $this->assertNotEmpty($assert_session->waitForText('Added one media item.'));
    +    $this->insertSelected('Added one media item.');
    

    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.

  10. +++ b/core/modules/media_library/tests/src/FunctionalJavascript/MediaLibraryTest.php
    @@ -560,50 +560,55 @@ public function testWidget() {
    -    // Assert the weight field can be focused via a mouse click.
    -    $assert_session->elementExists('named', ['button', 'Show media item weights'])->click();
    -    $assert_session->elementExists('css', '#field_twin_media-media-library-wrapper .media-library-item__weight')->click();
    -    $assert_session->elementExists('css', '#field_twin_media-media-library-wrapper .js-media-library-widget-toggle-weight')->click();
    +
    +    // Assert that we can toggle the visibility of the weight inputs.
    +    $wrapper = $assert_session->elementExists('css', '.field--name-field-twin-media');
    +    $wrapper->pressButton('Show media item weights');
    +    $assert_session->fieldExists('Weight', $wrapper)->click();
    +    $wrapper->pressButton('Hide media item weights');
    

    This is important accessibility test coverage and definitely should not rely on presentational CSS selectors.

  11. +++ b/core/modules/media_library/tests/src/FunctionalJavascript/MediaLibraryTest.php
    @@ -560,50 +560,55 @@ public function testWidget() {
    -    $this->waitForElementsCount('css', '.field--name-field-twin-media .media-library-item', 2);
    +    $this->waitForElementsCount('css', '.field--name-field-twin-media [data-media-library-item-delta]', 2);
    

    .media-library-item is presentational. [data-media-library-item-delta] is functional and added by the widget for accessibility reasons. :)

  12. +++ b/core/modules/media_library/tests/src/FunctionalJavascript/MediaLibraryTest.php
    @@ -560,50 +560,55 @@ public function testWidget() {
    -    $assert_session->elementExists('css', '.media-library-item__remove')->click();
    -    $this->assertNotEmpty($assert_session->waitForText('Removed Dog.'));
    -    $this->assertElementExistsAfterWait('css', '.media-library-item__remove')->click();
    -    $this->assertNotEmpty($assert_session->waitForText('Removed Dog.'));
    -    $assert_session->assertNoElementAfterWait('css', '.media-library-item__remove');
    +    $wrapper->pressButton('Remove');
    +    $this->waitForText('Removed Dog.');
    +    $wrapper->pressButton('Remove');
    +    $this->waitForText('Removed Dog.');
    +    $result = $wrapper->waitFor(10, function ($wrapper) {
    +      /** @var \Behat\Mink\Element\NodeElement $wrapper */
    +      return $wrapper->findButton('Remove') == NULL;
    +    });
    +    $this->assertTrue($result);
    

    This removes the reliance on presentational classes, and increases the precision of the assertions/interactions.

  13. +++ b/core/modules/media_library/tests/src/FunctionalJavascript/MediaLibraryTest.php
    @@ -560,50 +560,55 @@ public function testWidget() {
    -    $assert_session->elementExists('css', '.media-library-selected-count');
    -    $assert_session->elementTextContains('css', '.media-library-selected-count', '0 of 2 items selected');
    -    $assert_session->elementAttributeContains('css', '.media-library-selected-count', 'role', 'status');
    -    $assert_session->elementAttributeContains('css', '.media-library-selected-count', 'aria-live', 'polite');
    -    $assert_session->elementAttributeContains('css', '.media-library-selected-count', 'aria-atomic', 'true');
    +    $selected_count = $assert_session->elementExists('css', '.media-library-selected-count');
    +    $this->assertSame('0 of 2 items selected', $selected_count->getText());
    +    $this->assertSame('status', $selected_count->getAttribute('role'));
    +    $this->assertSame('polite', $selected_count->getAttribute('aria-live'));
    +    $this->assertSame('true', $selected_count->getAttribute('aria-atomic'));
    

    Again, .media-library-selected-count was repeated all over the place. There was no need for that, so I removed it.

  14. +++ b/core/modules/media_library/tests/src/FunctionalJavascript/MediaLibraryTest.php
    @@ -1203,37 +1185,28 @@ public function testWidgetUpload() {
    -    // Assert the focus is shifted to the added media items.
    -    $this->assertJsCondition('jQuery(".media-library-add-form__added-media").is(":focus")');
    -    // Assert the media item fields are shown and the vertical tabs are no
    -    // longer shown.
    -    $assert_session->elementExists('css', '.media-library-add-form__fields');
    -    $assert_session->elementNotExists('css', '.media-library-menu');
    +    $this->waitForFieldExists('Alternative text');
    +    $this->assertMediaAdded();
    

    The "added media" area has a lot of presentational classes in it. To abstract those away, I created assertMediaAdded() and assertNoMediaAdded().

  15. +++ b/core/modules/media_library/tests/src/FunctionalJavascript/MediaLibraryTest.php
    @@ -1563,15 +1523,14 @@ public function testWidgetUploadAdvancedUi() {
    -    $selection_area = $this->assertElementExistsAfterWait('css', '.media-library-add-form__selected-media');
    -    $assert_session->elementExists('css', 'summary', $selection_area)->click();
    +    $selection_area = $this->getSelectionArea();
    

    Same idea here -- getSelectionArea() is abstracting a presentational selector away.

  16. +++ b/core/modules/media_library/tests/src/FunctionalJavascript/MediaLibraryTest.php
    @@ -1872,33 +1808,25 @@ public function testWidgetOEmbed() {
    -    $this->assertJsCondition('jQuery(".media-library-add-form__added-media").is(":focus")');
    -    // Assert the media item fields are shown and the vertical tabs are no
    -    // longer shown.
    -    $assert_session->elementExists('css', '.media-library-add-form__fields');
    -    $assert_session->elementNotExists('css', '.media-library-menu');
    +    $this->assertMediaAdded();
    

    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.

  17. +++ b/core/modules/media_library/tests/src/FunctionalJavascript/MediaLibraryTest.php
    @@ -2228,21 +2141,35 @@ protected function assertElementExistsAfterWait($selector, $locator, $timeout =
       protected function switchToMediaType($type) {
    -    $page = $this->getSession()->getPage();
    -    $lowercase_type = strtolower($type);
    +    $link = $this->assertSession()
    +      ->elementExists('named', ['link', "Type $type"], $this->getTypesMenu());
     
    -    if (!is_null($page->find('css', ".media-library-menu-type-$lowercase_type .active-tab"))) {
    -      // There is nothing to do as the type is already active.
    +    if ($link->hasClass('active')) {
           return;
         }
    +    $link->click();
    +
    +    $result = $link->waitFor(10, function ($link) {
    +      /** @var \Behat\Mink\Element\NodeElement $link */
    +      return $link->hasClass('active');
    +    });
    +    $this->assertTrue($result);
     
    -    $page->clickLink($type);
    -    $this->assertElementExistsAfterWait('css', ".media-library-menu-type-$lowercase_type .active-tab");
    -    $this->assertElementExistsAfterWait('css', "[data-drupal-media-type='type_$lowercase_type']");
    

    Again, the idea here was to remove the reliance on CSS selectors in favor of functional markup.

  18. +++ b/core/modules/media_library/tests/src/FunctionalJavascript/MediaLibraryTest.php
    @@ -2359,9 +2286,69 @@ protected function pressSaveButton($expect_errors = FALSE) {
    +  /**
    +   * Asserts a media item was addd, but not yet saved.
    

    Whoops, typo.

phenaproxima’s picture

StatusFileSize
new127.78 KB

I 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.

phenaproxima’s picture

StatusFileSize
new140.17 KB

And, 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.

phenaproxima’s picture

+++ b/core/modules/media_library/src/Plugin/Field/FieldWidget/MediaLibraryWidget.php
@@ -365,21 +366,34 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen
+      // Ideally, this entire element would be themeable through a dedicated
+      // template. Unfortunately, the only way to do that while maintaining
+      // the proper form structure is via a #pre_render callback, which would
+      // necessarily change the form structure. And that, sadly, must be "just
+      // so" in order for various AJAX operations, like removing media items
+      // from the selection, to work correctly.
+      // @todo See if this can be done in $ISSUE_URL.
+      // @see ::removeItem()
+      // @see ::openMediaLibrary()
+      // @see ::updateWidget()

This is out of date and needs to be removed. :)

phenaproxima’s picture

StatusFileSize
new141.5 KB
new4.79 KB

A 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. 🤞

lauriii’s picture

I 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-item with card class.

Example 2: I'm implementing Media Library designs in Claro and I want to use our pre-existing action-link component for the edit link. I want to replace media-library-item__edit with action-link action-link--icon-pencil.

lauriii’s picture

Did 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_render to add the classes in a theme instead. This way the classes could be updated on fly without update hooks.

Example:

function seven_views_pre_render(&$element) {
  $element->field['edit_media']->options['alter']['link_class'] = 'media-library-item__edit';
}

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?

phenaproxima’s picture

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.

+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).

effulgentsia’s picture

Issue tags: +Needs change record

function seven_views_pre_render(&$element) {
$element->field['edit_media']->options['alter']['link_class'] = 'media-library-item__edit';
}

Nice 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.

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.

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.

We could recommend users who care about [cleaning up their Media Library View] to reinstall Media Library

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/import to do that and just paste in the YML from media_library/config/install/views.view.media_library.yml. Let's include that in the eventual CR that's written for this.

phenaproxima’s picture

StatusFileSize
new166.77 KB

I paired with @lauriii again and we went through the view, moving classes into either media_library_views_pre_render() or seven_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.

Status: Needs review » Needs work

The last submitted patch, 56: 3087456-56.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

phenaproxima’s picture

Some things from my walk-through with @effulgentsia:

  1. +++ b/core/modules/media_library/src/Form/AddFormBase.php
    @@ -445,7 +477,7 @@ protected function buildSelectedItemElement(MediaInterface $media, array $form,
    -      'rendered_entity' => $this->viewBuilder->view($media, 'media_library'),
    +      '#content' => $this->viewBuilder->view($media, 'media_library'),
    

    This isn't bueno. The media_library_item template should be a theme wrapper in order to avoid this.

  2. +++ b/core/modules/media_library/src/MediaLibraryUiBuilder.php
    @@ -123,14 +123,12 @@ public function buildUi(MediaLibraryState $state = NULL) {
    -        'menu' => $this->buildMediaTypeMenu($state),
    -        'content' => $this->buildLibraryContent($state),
    +        '#menu' => $this->buildMediaTypeMenu($state),
    +        '#content' => $this->buildLibraryContent($state),
    

    This should be using a render element in its theme hook, rather than two property/render arrays.

  3. +++ b/core/modules/media_library/tests/src/FunctionalJavascript/MediaLibraryTest.php
    @@ -439,8 +439,9 @@ public function testWidget() {
    +    // @todo: This should only be done in openMediaLibraryForField() when
    +    // testing in Seven, since only Seven has styles to add the checkbox.
    +    // $this->assertFalse($assert_session->elementExists('css', '.media-library-select-all')->isVisible());
    

    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.

  4. +++ b/core/themes/seven/seven.theme
    @@ -186,3 +188,184 @@ function seven_form_media_form_alter(&$form, FormStateInterface $form_state) {
    +/**
    + * Implements hook_preprocess_views_view_fields().
    + *
    + * This targets each rendered media item in the grid display of the media
    + * library's modal dialog.
    + */
    +function seven_preprocess_views_view_fields__media_library(array &$variables) {
    +  // Add classes to media rendered entity field so it can be targeted for
    +  // styling. Adding this class in a template is very difficult to do.
    +  if (isset($variables['fields']['rendered_entity']->wrapper_attributes)) {
    +    $variables['fields']['rendered_entity']->wrapper_attributes->addClass('media-library-item__click-to-select-trigger');
    +  }
    +}
    

    Can this be moved into seven_views_pre_render()? And more to the point, should we?

phenaproxima’s picture

Status: Needs work » Needs review
StatusFileSize
new168.32 KB
new1.29 KB

This should fix those dastardly test failures.

phenaproxima’s picture

StatusFileSize
new169.96 KB
new7.59 KB

Made the changes @effulgenstia requested (#1-3) in #58. This passed tests locally!

phenaproxima’s picture

StatusFileSize
new170.01 KB
new11.15 KB

@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:

  • Renamed the media_library theme hook to media_library_wrapper, for more accurate naming.
  • Removed an addition of the media-library-item__remove class from MediaLibraryWidget; it's already added by Seven, which is as it should be.
  • Deleted container--media-library-widget-item.html.twig, which is a defunct template from an earlier iteration of the patch.
  • Moved details--media-library-add-form-selected-media.html.twig from Classy to Seven, and added Seven-specific seven-details classes to it.
  • Added styling fixes to account for the fact that the "added media" list in AddFormBase is now a true item list.
  • Restored presentational classes (in Seven) for the preview and fields of each added media item. The classes are Seven-specific and present in HEAD, but were accidentally removed at some point in this whole kerfuffle.
phenaproxima’s picture

To 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.

lauriii’s picture

Status: Needs review » Needs work
  1. +++ b/core/modules/media_library/media_library.module
    @@ -91,7 +90,86 @@ function media_library_theme() {
    +      'render element' => 'element',
    ...
    +      'render element' => 'element',
    

    This 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. 🦖

  2. +++ b/core/modules/media_library/media_library.module
    @@ -91,7 +90,86 @@ function media_library_theme() {
    @@ -144,9 +222,7 @@ function media_library_preprocess_media(&$variables) {
    
    +++ b/core/themes/classy/templates/media-library/media--media-library.html.twig
    @@ -0,0 +1,50 @@
    + * @see template_preprocess_media()
    

    Let's add @see media_library_preprocess_media() here 📄

  3. +++ b/core/modules/media_library/media_library.module
    @@ -144,9 +222,7 @@ function media_library_preprocess_media(&$variables) {
         $variables['preview_attributes'] = new Attribute();
    ...
         $variables['metadata_attributes'] = new Attribute();
    

    Maybe out of scope but let's at least file a follow-up. We should check if preview_attributes or metadata_attributes have been set before. 🔬👁

  4. +++ b/core/modules/media_library/templates/media-library-item.html.twig
    @@ -0,0 +1,26 @@
    + * @file
    + * Default theme implementation of a container used to wrap child elements.
    + *
    + * Used for grouped form items. Can also be used as a theme wrapper for any
    + * renderable element, to surround it with a <div> and HTML attributes.
    + * See \Drupal\Core\Render\Element\RenderElement for more
    + * information on the #theme_wrappers render array property, and
    + * \Drupal\Core\Render\Element\container for usage of the container render
    + * element.
    + *
    + * Available variables:
    + * - attributes: HTML attributes for the containing element.
    + * - children: The rendered child elements of the container.
    + *
    + * @see template_preprocess_container()
    + *
    + * @ingroup themeable
    
    +++ b/core/themes/classy/templates/media-library/media-library-item--small.html.twig
    @@ -0,0 +1,33 @@
    + *
    + * Available variables:
    + * - attributes: HTML attributes for the containing element.
    + * - children: The rendered child elements of the container.
    + *
    + * @see template_preprocess_container()
    + *
    + * @ingroup themeable
    
    +++ b/core/themes/classy/templates/media-library/media-library-item.html.twig
    @@ -0,0 +1,32 @@
    + *
    + * Available variables:
    + * - attributes: HTML attributes for the containing element.
    + * - children: The rendered child elements of the container.
    + *
    + * @see template_preprocess_container()
    + *
    

    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

    @see seven_preprocess_media_library_item__small()
    @see seven_preprocess_media_library_item__widget()
    
  5. +++ b/core/modules/media_library/templates/media-library-wrapper.html.twig
    @@ -0,0 +1,19 @@
    + *
    + * @ingroup themeable
    
    +++ b/core/themes/classy/templates/media-library/media-library-wrapper.html.twig
    @@ -0,0 +1,24 @@
    + *
    + * @ingroup themeable
    

    Let's add @see template_preprocess_media_library_wrapper() 📄

  6. +++ b/core/themes/classy/classy.theme
    @@ -0,0 +1,25 @@
    +  // Ideally this would be done in a template, but it's very difficult for
    +  // templates to access the correct place to set classes on the link, and it's
    +  // impossible to recursively merge arrays (i.e., attribute arrays) within
    +  // templates.
    

    Can we open follow-up for this? 💼

  7. +++ b/core/themes/classy/templates/media-library/container--media-library-content.html.twig
    @@ -0,0 +1,27 @@
    + * Default theme implementation of a container used to wrap child elements.
    + *
    + * Used for grouped form items. Can also be used as a theme wrapper for any
    + * renderable element, to surround it with a <div> and HTML attributes.
    + * See \Drupal\Core\Render\Element\RenderElement for more
    + * information on the #theme_wrappers render array property, and
    + * \Drupal\Core\Render\Element\container for usage of the container render
    + * element.
    
    +++ b/core/themes/classy/templates/media-library/container--media-library-widget-selection.html.twig
    @@ -0,0 +1,27 @@
    + * Default theme implementation of a container used to wrap child elements.
    + *
    + * Used for grouped form items. Can also be used as a theme wrapper for any
    + * renderable element, to surround it with a <div> and HTML attributes.
    + * See \Drupal\Core\Render\Element\RenderElement for more
    + * information on the #theme_wrappers render array property, and
    + * \Drupal\Core\Render\Element\container for usage of the container render
    + * element.
    
    +++ b/core/themes/classy/templates/media-library/links--media-library-menu.html.twig
    @@ -0,0 +1,55 @@
    + * Theme override for a set of links.
    
    +++ b/core/themes/classy/templates/media-library/media--media-library.html.twig
    @@ -0,0 +1,50 @@
    + * Default theme implementation to present a media entity in the media library.
    
    +++ b/core/themes/classy/templates/media-library/media-library-item--small.html.twig
    @@ -0,0 +1,33 @@
    + * Default theme implementation of a container used to wrap child elements.
    + *
    + * Used for grouped form items. Can also be used as a theme wrapper for any
    + * renderable element, to surround it with a <div> and HTML attributes.
    + * See \Drupal\Core\Render\Element\RenderElement for more
    + * information on the #theme_wrappers render array property, and
    + * \Drupal\Core\Render\Element\container for usage of the container render
    + * element.
    
    +++ b/core/themes/classy/templates/media-library/media-library-wrapper.html.twig
    @@ -0,0 +1,24 @@
    + * Default theme implementation of a container used to wrap the media library's
    + * modal dialog interface.
    
    +++ b/core/themes/classy/templates/media-library/views-view-unformatted--media-library.html.twig
    @@ -0,0 +1,32 @@
    + * Theme override to display a view of unformatted rows.
    
    +++ b/core/themes/seven/media-library/details--media-library-add-form-selected-media.html.twig
    @@ -0,0 +1,45 @@
    + * Theme override for a details element.
    
    +++ b/core/themes/seven/media-library/fieldset--media-library-widget.html.twig
    @@ -0,0 +1,63 @@
    + * Theme override for a fieldset element and its children.
    
    +++ b/core/themes/seven/media-library/item-list--media-library-add-form-media-list.html.twig
    @@ -0,0 +1,31 @@
    + * Theme override for an item list.
    

    Docs need updating 📄

  8. +++ b/core/themes/classy/templates/media-library/container--media-library-content.html.twig
    @@ -0,0 +1,27 @@
    +{%
    +  set classes = [
    +    'media-library-content',
    +  ]
    +%}
    
    +++ b/core/themes/classy/templates/media-library/container--media-library-widget-selection.html.twig
    @@ -0,0 +1,27 @@
    +{%
    +  set classes = [
    +    'media-library-selection',
    +  ]
    +%}
    
    +++ b/core/themes/classy/templates/media-library/media-library-wrapper.html.twig
    @@ -0,0 +1,24 @@
    +  set classes = [
    +  'media-library-wrapper',
    +]
    +%}
    

    It seems unnecessary to create a local variable for adding a single class. 🚣‍♂️

  9. +++ b/core/themes/classy/templates/media-library/links--media-library-menu.html.twig
    @@ -0,0 +1,55 @@
    + * @see template_preprocess_links()
    

    Let's add @see classy_preprocess_links__media_library_menu() here. 📄

  10. +++ b/core/themes/seven/media-library/fieldset--media-library-widget.html.twig
    @@ -0,0 +1,63 @@
    + * @see template_preprocess_fieldset()
    

    Let's add @see seven_preprocess_fieldset__media_library_widget() here 📄

  11. +++ b/core/themes/seven/media-library/item-list--media-library-add-form-media-list.html.twig
    @@ -0,0 +1,31 @@
    + * @see template_preprocess_item_list()
    

    Let's add @see seven_preprocess_item_list__media_library_add_form_media_list() here 📄

phenaproxima’s picture

Status: Needs work » Needs review
StatusFileSize
new100.46 KB

Rerolled 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!

phenaproxima’s picture

StatusFileSize
new101.21 KB
new16.86 KB

Addressing #63:

  1. 👎@effulgentsia had requested this so that we wouldn't be passing sub-render arrays as properties of a parent render array. Leaving as-is.
  2. ✅Decided to fix it here. It's not worth a follow-up.
  3. ✅How's this look?
  4. ✅Filed #3088856: Make it possible/easier to apply CSS classes to links in the links template about this and linked it in the code.
  5. ✅Okay, gave it a shot. What do you think?
  6. ✅Agreed. Fixed.

Also fixing a dumb mistake in #64 which will cause tests to fail.

The last submitted patch, 64: 3087456-64.patch, failed testing. View results

effulgentsia’s picture

Re #65.1, right, here's more places related to that...

  1. +++ b/core/modules/media_library/src/MediaLibraryUiBuilder.php
    @@ -123,14 +123,12 @@ public function buildUi(MediaLibraryState $state = NULL) {
    -        'menu' => $this->buildMediaTypeMenu($state),
    -        'content' => $this->buildLibraryContent($state),
    +        '#menu' => $this->buildMediaTypeMenu($state),
    +        '#content' => $this->buildLibraryContent($state),
    

    Render arrays should not be assigned to #properties, so this change moves in the wrong direction.

  2. +++ b/core/modules/media_library/src/Form/AddFormBase.php
    @@ -416,12 +447,14 @@ protected function buildCurrentSelectionArea(array $form, FormStateInterface $fo
    +      '#theme_wrappers' => [
    +        'media_library_item__small',
    +      ],
    +++ b/core/modules/media_library/src/Plugin/Field/FieldWidget/MediaLibraryWidget.php
    @@ -365,21 +367,26 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen
    +        '#theme_wrappers' => [
    +          'media_library_item__widget',
    +        ],
    

    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.

  3. +++ b/core/modules/media_library/src/Form/AddFormBase.php
    @@ -366,6 +351,54 @@ protected function buildEntityFormElement(MediaInterface $media, array $form, Fo
    +    $element['#content_prefix']['select'] = $element['select'];
    +    unset($element['select']);
    +++ b/core/modules/media_library/src/Plugin/Field/FieldWidget/MediaLibraryWidget.php
    @@ -558,6 +560,54 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen
    +    $element['#content_suffix']['weight'] = $element['weight'];
    +    $element['#content_suffix']['target_id'] = $element['target_id'];
    +    $element['#content_prefix']['remove_button'] = $element['remove_button'];
    +    unset($element['weight'], $element['target_id'], $element['remove_button']);
    

    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.

phenaproxima’s picture

StatusFileSize
new96.56 KB
new11.71 KB

I 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 :)

effulgentsia’s picture

+++ b/core/modules/media_library/js/media_library.view.es6.js
@@ -21,7 +21,7 @@
-              .closest('.media-library-view')
+              .closest('.js-media-library-view')
+++ b/core/modules/media_library/tests/src/FunctionalJavascript/MediaLibraryTest.php
@@ -829,13 +820,13 @@ public function testWidgetViews() {
-    $assert_session->elementTextContains('css', '.view-media-library .pager__item.is-active', 'Page 1');
+    $assert_session->elementTextContains('css', '.js-media-library-view .pager__item.is-active', 'Page 1');
...
-    $this->waitForElementTextContains('.view-media-library .pager__item.is-active', 'Page 2');
+    $this->waitForElementTextContains('.js-media-library-view .pager__item.is-active', 'Page 2');
...
-    $this->waitForElementTextContains('.view-media-library .pager__item.is-active', 'Page 1');
+    $this->waitForElementTextContains('.js-media-library-view .pager__item.is-active', 'Page 1');

Looks like this didn't make it into #3088681: Make MediaLibraryTest less dependent on representational CSS selectors. Can we open a new issue for it?

effulgentsia’s picture

+++ b/core/modules/media_library/src/Form/AddFormBase.php
@@ -629,13 +637,13 @@ public function updateFormCallback(array &$form, FormStateInterface $form_state)
-        $response->addCommand(new InvokeCommand(".media-library-add-form__media[data-media-library-added-delta=$delta_to_focus]", 'focus'));
+        $response->addCommand(new InvokeCommand("[data-media-library-added-delta=$delta_to_focus]", 'focus'));
...
-      $response->addCommand(new InvokeCommand('.media-library-add-form__added-media', 'focus'));
+      $response->addCommand(new InvokeCommand('.js-media-library-add-form-added-media', 'focus'));

Same for this. Can be part of the same issue as #69.

effulgentsia’s picture

diff --git a/core/modules/media_library/tests/src/FunctionalJavascript/ContentModerationTest.php b/core/modules/media_library/tests/src/FunctionalJavascript/ContentModerationTest.php
...
diff --git a/core/modules/media_library/tests/src/FunctionalJavascript/TranslationsTest.php b/core/modules/media_library/tests/src/FunctionalJavascript/TranslationsTest.php

Same for this. Can also be part of the same issue as #69.

effulgentsia’s picture

  1. +++ b/core/modules/media_library/tests/src/FunctionalJavascript/MediaLibraryTest.php
    @@ -993,13 +982,11 @@ public function testWidgetUpload() {
    -    $assert_session->elementExists('css', '.media-library-add-form--without-input');
    ...
    -    $assert_session->elementNotExists('css', '.media-library-add-form--without-input');
    

    Why are we removing this test coverage?

  2. +++ b/core/modules/media_library/tests/src/FunctionalJavascript/MediaLibraryTest.php
    @@ -2025,9 +1993,11 @@ public function testFieldUiIntegration() {
    -    $page->pressButton('Save field settings');
    +    while ($button = $page->findButton('Save field settings')) {
    +      $button->press();
    +    }
         $assert_session->pageTextNotContains('Undefined index: target_bundles');
    -    $page->checkField('settings[handler_settings][target_bundles][type_one]');
    +    $this->waitForFieldExists('settings[handler_settings][target_bundles][type_one]')->check();
    

    Is this related to this issue? If so, how?

effulgentsia’s picture

+++ b/core/themes/classy/templates/media-library/links--media-library-menu.html.twig
+++ b/core/themes/classy/templates/media-library/media--media-library.html.twig
+++ b/core/themes/seven/media-library/details--media-library-add-form-selected-media.html.twig
+++ b/core/themes/seven/media-library/fieldset--media-library-widget.html.twig

These 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.,

{% extends "links.html.twig" %}
{% set attributes = attributes.addClass('media-library-menu') %}

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.

effulgentsia’s picture

  1. --- a/core/modules/media_library/templates/media--media-library.html.twig
    +++ b/core/modules/media_library/templates/media--media-library.html.twig
    

    We 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?

  2. +++ b/core/modules/media_library/templates/media-library-item.html.twig
    +++ b/core/modules/media_library/templates/media-library-wrapper.html.twig
    

    Do we need to add copies of these in Stable as well?

effulgentsia’s picture

+++ b/core/themes/classy/templates/media-library/container--media-library-content.html.twig
+++ b/core/themes/classy/templates/media-library/container--media-library-widget-selection.html.twig

Because these are containers, should we also add the has_parent ? ['js-form-wrapper', 'form-wrapper'] classes too, for consistency with Classy's container.html.twig?

effulgentsia’s picture

Status: Needs review » Needs work

NW for addressing #69 - #75, whether that means fixing the patch, or commenting as to why the feedback is incorrect.

phenaproxima’s picture

Assigned: Unassigned » phenaproxima

Self-assigning to deal with all that.

phenaproxima’s picture

StatusFileSize
new95.6 KB
new4.74 KB

Addressing #72:

  1. That was removed since those classes are only being added by Seven's form_alter implementations. However, now that we have MediaLibrarySevenTest, we can easily re-add that coverage. So that's what I did :)
  2. Good catch. It is not related; that's detritus from me trying to rein in a test which never random-fails on testbot, as far as I could tell, but constantly random-fails on my local machine. It's not needed for this patch.

Addressing #73:

I was able to change this in two of the templates. The two I couldn't change -- fieldset--media-library-widget.html.twig and media--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:

  1. I think this is a pre-existing template, so I'm not sure if we can or should add it to Stable here. Maybe in the main "stable-maker" patch? 🤷‍♂️
  2. These are new templates, so they do belong in Stable, but maybe that should also be done in the main stable-maker too. This is probably a question for the front-end framework manager.

I'm leaving these as-is for now.

Addressing #75:

I decided to leave these as-is for now. has_parent isn't really super relevant to theming these things; we're using container for 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 any has_parent stuff 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_parent and its related classes if wanted.

phenaproxima’s picture

lauriii’s picture

#74.1 & 2 Adding templates to Stable should be done as part of the stable maker patch. 👍

Status: Needs review » Needs work

The last submitted patch, 78: 3087456-78.patch, failed testing. View results

phenaproxima’s picture

Status: Needs work » Needs review
StatusFileSize
new95.91 KB
new1.15 KB

Whoops, sorry! Accidentally removed some stuff from MediaLibraryTest::testFieldUiIntegration() that should still be there.

phenaproxima’s picture

Rerolled 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!

phenaproxima’s picture

Discussed #75 with @effulgentsia. We agreed that our specialized container templates should probably not deviate too much from the default template for containers, so kicking this back to "needs work" to restore the has_parent flag, 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.

phenaproxima’s picture

Status: Needs review » Needs work

to reduce noise in this issue.

Mission not accomplished! 😛

phenaproxima’s picture

Status: Needs work » Needs review
StatusFileSize
new73.94 KB

OK, 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.

phenaproxima’s picture

StatusFileSize
new73.94 KB

Looks 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...

phenaproxima’s picture

Issue tags: -Needs change record

I 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. :)

phenaproxima’s picture

Also... @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.

phenaproxima’s picture

Crediting @lauriii and @effulgentsia for guidance, pairing, and reviews.

phenaproxima’s picture

Assigned: phenaproxima » Unassigned

I think it's time I un-assigned this.

effulgentsia’s picture

Status: Needs review » Reviewed & tested by the community

I 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.css and media_library.theme.css. One example is the media-library-view class, 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).

phenaproxima’s picture

I 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.css and media_library.theme.css. One example is the media-library-view class, but there are also a few others.

This 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.css and module.css files) 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. :)

phenaproxima’s picture

Linking the "stable maker" I keep talking about, so that future readers of this issue will be able to find it.

lauriii’s picture

Status: Reviewed & tested by the community » Needs work
  1. To address #92 I'd recommend we move this to the stable maker patch.
  2. Something I realized about the stable maker is that the only remaining CSS selector .media-library-view--widget .media-library-select-all will break on Stark and Stable as a result of this patch. Could this be replaced with a visually-hidden class for example?
  3. +++ b/core/themes/classy/templates/media-library/container--media-library-content.html.twig
    @@ -0,0 +1,27 @@
    +  set classes = [
    +    has_parent ? 'js-form-wrapper',
    +    has_parent ? 'form-wrapper',
    +  ]
    +%}
    +<div{{ attributes.addClass('media-library-content') }}>{{ children }}</div>
    
    +++ b/core/themes/classy/templates/media-library/container--media-library-widget-selection.html.twig
    @@ -0,0 +1,27 @@
    +{%
    +  set classes = [
    +    has_parent ? 'js-form-wrapper',
    +    has_parent ? 'form-wrapper',
    +  ]
    +%}
    +<div{{ attributes.addClass('media-library-selection') }}>{{ children }}</div>
    

    The classes variable is not being used at the moment at all. 🔬👁

  4. +++ b/core/themes/classy/classy.theme
    @@ -0,0 +1,21 @@
    + *   https://www.drupal.org/project/drupal/issues/3088856 is resolved.
    
    +++ b/core/themes/classy/templates/media-library/media--media-library.html.twig
    @@ -0,0 +1,55 @@
    +    <div{{ preview_attributes.addClass('media-library-item__preview js-media-library-item-preview') }}>
    +      {{ content|without('name') }}
    +    </div>
    ...
    +      <div class="media-library-item__name">
    +        {{ name }}
    +      </div>
    

    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.

phenaproxima’s picture

Something I realized about the stable maker is that the only remaining CSS selector .media-library-view--widget .media-library-select-all will break on Stark and Stable as a result of this patch. Could this be replaced with a visually-hidden class for example?

I don't think so, because visually-hidden will still keep it accessible to screen readers. We want to suppress it entirely, which is why it uses display: 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-all class to the widget displays in media_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?

To address #92 I'd recommend we move this to the stable maker patch.

I'm not sure what "this" is referring to here?

lauriii’s picture

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.

This seems like a good solution to this 👍

I'm not sure what "this" is referring to here?

I was suggesting not to make a commit in this issue but instead, add these changes to be part of the stable maker issue.

phenaproxima’s picture

Status: Needs work » Needs review
StatusFileSize
new75.66 KB
new5 KB

Addressing #95:

  1. 👍 Sure, okay. No problem; please just mark the issue fixed when the patch looks like something you would commit, and I'll transfer our work to the stable-maker.
  2. ✅ Changed the JavaScript so that the "select all" is only added to .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!
  3. 👀 Ooh, nice catch! Fixed.
  4. Still need to open this, but 👍
phenaproxima’s picture

lauriii’s picture

Status: Needs review » Needs work
+++ b/core/modules/media_library/js/media_library.view.es6.js
@@ -12,7 +12,7 @@
-      const $view = $('.js-media-library-view', context).once(
+      const $view = $('.js-media-library-view.view-display-id-page', context).once(

This is not a reliable way to determine the display id because this is only added in Classy.

lauriii’s picture

Discussed with @phenaproxima about how to recognize the View ID reliably and we agreed that we would use hook_preprocess_views_view in the Media Library module to add a new data attribute for the View ID.

phenaproxima’s picture

Discussed with @phenaproxima about how to recognize the View ID reliably and we agreed that we would use hook_preprocess_views_view in the Media Library module to add a new data attribute for the View ID.

Almost. 😛 It's the display ID I need, not the view ID. So I'll add this data attribute to the media_library view only, and it will contain the display ID for targeting.

lauriii’s picture

Almost. 😛 It's the display ID I need, not the view ID. So I'll add this data attribute to the media_library view only, and it will contain the display ID for targeting.

Sounds good 😅

phenaproxima’s picture

Status: Needs work » Needs review
StatusFileSize
new77.03 KB
new3.27 KB

Okay! This addresses #100.

phenaproxima’s picture

StatusFileSize
new77.17 KB
new785 bytes

Forgot to run yarn prettier on the previous patch. 🙄

bnjmnm’s picture

Status: Needs review » Reviewed & tested by the community

Looks like all the feedback is properly addressed and it's been scrutinized by Drupal's finest, so RTBC.

lauriii’s picture

Status: Reviewed & tested by the community » Fixed

All my feedback has been addressed. Let’s move the patch to the stable maker issue.

lauriii’s picture

Status: Fixed » Needs work

I just noticed that the grep I did yesterday excluded the .module file 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 from media_library_preprocess_views_view_fields and _media_library_views_form_media_library_after_build to themes.

phenaproxima’s picture

Status: Needs work » Needs review
StatusFileSize
new79.79 KB
new3.79 KB

This patch fixes #108 thusly:

  • I removed the media-library-item__click-to-select-trigger class from media_library_preprocess_views_view_fields(). The previous patch already moved it to seven_preprocess_views_view_fields__media_library().
  • I moved the after_build callback, and the related stuff in media_library_form_alter(), to Seven.
lauriii’s picture

Status: Needs review » Reviewed & tested by the community

Looks good! Feel free to mark this as fixed once this has been added to the stable maker.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 109: 3087456-109.patch, failed testing. View results

phenaproxima’s picture

The 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.

phenaproxima’s picture

Status: Needs work » Needs review
StatusFileSize
new79.52 KB
new3.36 KB

OK. 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--actions class is in Seven, as it should be.

Status: Needs review » Needs work

The last submitted patch, 113: 3087456-113.patch, failed testing. View results

phenaproxima’s picture

Status: Needs work » Needs review
StatusFileSize
new78.95 KB
new1.79 KB

Well, okay. This oughta do the trick.

phenaproxima’s picture

StatusFileSize
new79.42 KB
new1.23 KB

Improving and expanding a comment for accuracy, per @lauriii's request.

phenaproxima’s picture

StatusFileSize
new79.51 KB

Oh, 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.

phenaproxima’s picture

StatusFileSize
new79.51 KB
lauriii’s picture

Status: Needs review » Reviewed & tested by the community

Looks 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.

phenaproxima’s picture

Status: Reviewed & tested by the community » Fixed

#3082690-62: Mark Media Library as a stable core module already includes #118, so that's done. Marking fixed. Thanks!

Status: Fixed » Closed (fixed)

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