Problem/Motivation

The current Media administration experience is not very visual, and does not look like what most people expect from a CMS.

Proposed resolution

We should update the view at /admin/content/media to look more modern - displaying a grid of media cards that show a preview of the media and metadata (attributes/fields) that make sense for each media item.

To give more flexibility to site builders and themers, each media item in the library is rendered in a new view mode called "Media Library", which is customizable like any other view mode.

This updated view will also be the basis for a new Field Widget, to allow visual selection of Media while editing/creating content. This widget will be added in another issue, but part of why this is being added in a new experimental module is to have a place for us to iterate on the widget and other code related to the Media Library experience.

Review the current patch. Discuss UX feedback.

Note for committers - on commit, please ensure that "jan.stoeckler, webflo, seanB, chr.fritsch, DyanneNova, yoroy, dennis-cohn, rfmarcelino, andrewmacpherson, benjifisher" is added to the issue credits. This is ported over from #2834729: [META] Roadmap to stabilize Media Library.

User interface changes

The view at /admin/content/media looks different, but is functionally the same.

API changes

None.

Data model changes

None.

CommentFileSizeAuthor
#136 2962110-136.patch23.84 KBMingsong
#124 2962110-124-media.png130.11 KBphenaproxima
#124 2962110-124-media-library.png119.93 KBphenaproxima
#115 interdiff-2962110-100-115-0.txt5.74 KBsamuel.mortenson
#115 2962110-115-0.patch54.04 KBsamuel.mortenson
#100 interdiff-2962110-96-100.txt8.06 KBsamuel.mortenson
#100 2962110-100.patch53.87 KBsamuel.mortenson
#96 interdiff-2962110-90-96.txt568 bytessamuel.mortenson
#96 2962110-96.patch54.69 KBsamuel.mortenson
#90 interdiff-2962110-87-90.txt11.04 KBsamuel.mortenson
#90 2962110-90.patch54.63 KBsamuel.mortenson
#87 interdiff-2962110-81-87.txt597 bytessamuel.mortenson
#87 2962110-87.patch54.48 KBsamuel.mortenson
#81 2962110-81.patch54.42 KBsamuel.mortenson
#81 interdiff-2962110-67-81.txt10.2 KBsamuel.mortenson
#79 media-79.png250.41 KBckrina
#76 select-all-checkbox.jpg139.12 KByoroy
#67 media-library-2018-05-28.png319.19 KBsamuel.mortenson
#67 interdiff-2962110-65-67.txt4.66 KBsamuel.mortenson
#67 2962110-67.patch53.5 KBsamuel.mortenson
#66 66-grid-table-proposal.png195.42 KBckrina
#65 interdiff-2962110-58-65.txt11.12 KBsamuel.mortenson
#65 2962110-65.patch52.28 KBsamuel.mortenson
#58 interdiff-2962110-51-58.txt4.77 KBsamuel.mortenson
#58 2962110-58.patch53.22 KBsamuel.mortenson
#54 bulk-media.png267.65 KBckrina
#53 mvp-bulk-media.png110.49 KBckrina
#51 media-library-icon-size-fix.png251.27 KBsamuel.mortenson
#51 interdiff-2962110-44-50.txt2.95 KBsamuel.mortenson
#51 2962110-50.patch52.7 KBsamuel.mortenson
#48 2962110-48-no-thumbnails.png17.62 KBphenaproxima
#48 2962110-48-generic-icon-too-big.png16.56 KBphenaproxima
#46 2962110-44-buttons-list.PNG12.6 KBandrewmacpherson
#46 2962110-44-links-list.PNG13.61 KBandrewmacpherson
#45 2962110-44-NVDA-form-fields-list.png20.16 KBandrewmacpherson
#45 2962110-44-windows-high-contrast-borders-on-focused-media-label-links-FIXED.PNG272.11 KBandrewmacpherson
#44 interdiff-2962110-42-44.txt7.78 KBsamuel.mortenson
#44 2962110-44.patch52.05 KBsamuel.mortenson
#42 2962110-42.patch51.63 KBsamuel.mortenson
#42 interdiff-2962110-40-42.txt1.15 KBsamuel.mortenson
#40 interdiff-2962110-37-40.txt1.25 KBsamuel.mortenson
#40 2962110-40.patch51.67 KBsamuel.mortenson
#40 interdiff-2962110-37-40.txt1.53 KBsamuel.mortenson
#38 2962110-38-windows-high-contrast-borders-on-all-media-label-links.png196.09 KBandrewmacpherson
#38 2962110-38-media-library-grid-layout-bug-ms-edge.png216.61 KBandrewmacpherson
#37 interdiff-2962110-36-37.txt8.95 KBsamuel.mortenson
#37 2962110-37.patch51.65 KBsamuel.mortenson
#36 2962110-36.patch48.08 KBGrandmaGlassesRopeMan
#36 interdiff-2962110-28-36.txt5.85 KBGrandmaGlassesRopeMan
#28 interdiff-2962110-24-28.txt1.53 KBsamuel.mortenson
#28 2962110-28.patch47.9 KBsamuel.mortenson
#28 screenshot-2962110-28.png375.09 KBsamuel.mortenson
#24 media-library-ux-update.png372.8 KBsamuel.mortenson
#24 interdiff-2962110-20-24.txt16.67 KBsamuel.mortenson
#24 2962110-24.patch48.24 KBsamuel.mortenson
#22 mediaA.png176.18 KBckrina
#20 interdiff-2962110-17-20.txt1.25 KBsamuel.mortenson
#20 2962110-20.patch49.27 KBsamuel.mortenson
#17 interdiff-2962110-13-17.txt16.5 KBsamuel.mortenson
#17 2962110-17.patch49.23 KBsamuel.mortenson
#13 interdiff-2962110-12-13.txt5.68 KBsamuel.mortenson
#13 2962110-13.patch46.91 KBsamuel.mortenson
#12 2962110-12.patch46.52 KBsamuel.mortenson
#12 interdiff-2962110-11-12.txt1.06 KBsamuel.mortenson
#11 interdiff-2962110-9-11.txt658 bytessamuel.mortenson
#11 2962110-11.patch46.51 KBsamuel.mortenson
#9 interdiff-2962110-1-9.txt15.7 KBsamuel.mortenson
#9 2962110-9.patch46.62 KBsamuel.mortenson
#5 Screen Shot 2018-04-18 at 19.40.43.png56.82 KBckrina
#2 2962110-1.patch46.46 KBsamuel.mortenson
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

samuel.mortenson created an issue. See original summary.

samuel.mortenson’s picture

Status: Active » Needs review
FileSize
46.46 KB

Here's the patch moved from #2834729-72: [META] Roadmap to stabilize Media Library. Here's the unaddressed review:

  1. +++ b/core/composer.json
    --- /dev/null
    +++ b/core/misc/icons/787878/check.svg
    

    Do we need additional variants of this icon for other color schemes? (That's probably a question for the UX team.)

  2. +++ b/core/modules/media_library/config/install/views.view.media_library.yml
    @@ -0,0 +1,418 @@
    +          row_class: media-library-item
    

    Let's change this class to something more generic, so that we can (ideally) bring this click-to-select functionality into Views. Any ideas for what to call it? Maybe 'click-to-select'?

  3. +++ b/core/modules/media_library/config/install/views.view.media_library.yml
    @@ -0,0 +1,418 @@
    +        media_bulk_form:
    

    Again, to groom this functionality for inclusion into Views, let's rename the plugin now (click_to_select or something like that, or maybe just 'selection').

  4. +++ b/core/modules/media_library/config/install/views.view.media_library.yml
    @@ -0,0 +1,418 @@
    +          element_class: media-library-item-checkbox
    

    Same here.

  5. +++ b/core/modules/media_library/config/install/views.view.media_library.yml
    @@ -0,0 +1,418 @@
    +          element_class: media-library-item-content
    

    Should this also be made "generic"? If so, something like 'selectable-content' might make more sense.

  6. +++ b/core/modules/media_library/config/install/views.view.media_library.yml
    @@ -0,0 +1,418 @@
    +      filters:
    

    I will be demoing the library to the UX team today and will ask them about the filters. Specifically, whether we have enough, or should have different ones out of the box.

  7. +++ b/core/modules/media_library/config/optional/core.entity_view_display.media.audio.media_library.yml
    @@ -0,0 +1,29 @@
    +    - field.field.media.audio.field_media_audio_file
    

    Why is this dependency here? It's not used in the view display; it's really just a dependency of the media type, no? Can we remove it, or was it automatically calculated?

  8. +++ b/core/modules/media_library/config/optional/core.entity_view_display.media.file.media_library.yml
    @@ -0,0 +1,29 @@
    +    - field.field.media.file.field_media_file
    

    Same here.

  9. +++ b/core/modules/media_library/config/optional/core.entity_view_display.media.image.media_library.yml
    @@ -0,0 +1,29 @@
    +    - field.field.media.image.field_media_image
    

    Same here.

  10. +++ b/core/modules/media_library/config/optional/core.entity_view_display.media.video.media_library.yml
    @@ -0,0 +1,29 @@
    +    - field.field.media.video.field_media_video_file
    

    And here.

  11. +++ b/core/modules/media_library/css/media_library.css
    @@ -0,0 +1,144 @@
    +#views-form-media-library-page {
    +  display: flex;
    +  flex-wrap: wrap;
    +  align-content: space-between;
    +}
    

    It's SO nice to be able to use flexbox. However, I wonder if we shouldn't make these into generic classes so as to eventually merge this CSS into Views.

  12. +++ b/core/modules/media_library/css/media_library.css
    @@ -0,0 +1,144 @@
    +  font-size: 12px;
    

    I'm not entirely certain we're supposed to size type in pixels. This file needs review from a CSS expert who knows the standard practices for core CSS.

  13. +++ b/core/modules/media_library/js/media_library.view.es6.js
    @@ -0,0 +1,63 @@
    +        // Links inside the rendered media item should not be click-able.
    +        event.preventDefault();
    

    I'm not sure this will have the intended effect (to prevent links in the rendered content from being clicked). If it indeed does, we should prove that with a functional JavaScript test.

  14. +++ b/core/modules/media_library/js/media_library.view.es6.js
    @@ -0,0 +1,63 @@
    +        $(this).parents('.media-library-item').toggleClass('checked', $input.prop('checked'));
    

    Can we use .closest() here, for clarity?

  15. +++ b/core/modules/media_library/js/media_library.view.es6.js
    @@ -0,0 +1,63 @@
    +        if ($('.media-library-item.checked').length) {
    

    Can't we just check $input.prop('checked')?

  16. +++ b/core/modules/media_library/js/media_library.view.es6.js
    @@ -0,0 +1,63 @@
    +      // Add the toggle when javascript is available
    

    I don't think we need this comment. Anything in a JavaScript file will only be taking place if JavaScript is available :)

  17. +++ b/core/modules/media_library/js/media_library.view.es6.js
    @@ -0,0 +1,63 @@
    +        $(this).parents('.media-library-item').toggleClass('expanded');
    

    I think we can prefer .closest().

  18. +++ b/core/modules/media_library/js/media_library.view.es6.js
    @@ -0,0 +1,63 @@
    +      $('.media-library-item .media-library-item-preview', context).once('media-library-item').on('mouseover', function () {
    +        $(this).parents('.media-library-item').addClass('is-hover');
    +      }).on('mouseout', function () {
    +        $(this).parents('.media-library-item').removeClass('is-hover');
    +      });
    

    I think we could use .closest() here too.

  19. +++ b/core/modules/media_library/media_library.info.yml
    @@ -0,0 +1,10 @@
    +  - drupal:user
    

    Not a big deal, but why do we have the explicit dependency on User?

  20. +++ b/core/modules/media_library/media_library.libraries.yml
    @@ -0,0 +1,17 @@
    +  dependencies:
    +    - core/drupal
    +    - core/jquery
    +    - core/jquery.once
    

    I believe jquery.once already depends on jquery, so we can remove the explicit jquery dependency.

  21. +++ b/core/modules/media_library/media_library.links.action.yml
    @@ -0,0 +1,5 @@
    +media_library.add:
    +  route_name: entity.media.add_page
    +  title: 'Add media'
    +  appears_on:
    +    - view.media_library.page
    

    The test should assert that this link actually appears.

  22. +++ b/core/modules/media_library/media_library.module
    @@ -0,0 +1,84 @@
    +/**
    + * Displays a timestamp in a human-readable fashion.
    + *
    + * @todo This might be suitable for core as a Twig function.
    + *
    + * @param int $time
    + *   A timestamp.
    + *
    + * @return \Drupal\Core\StringTranslation\TranslatableMarkup
    + *   Markup representing a formatted time.
    + */
    

    If we're going to move this into core as a Twig function, let's also mark it @internal.

  23. +++ b/core/modules/media_library/templates/media--media-library.html.twig
    @@ -0,0 +1,52 @@
    + * Other themes are welcome to override this template, as long as the
    + * "media-library-item-preview" and "media-library-item-attributes" classes are
    + * present in the template override.
    

    Would it helpful to use data attributes, and/or Attributes objects, for these purposes? Like <div data-media-library-component="preview"> and <div data-media-library-component="attributes"> or something? It might separate the concerns a little more cleanly.

  24. +++ b/core/modules/media_library/templates/media--media-library.html.twig
    @@ -0,0 +1,52 @@
    + * - created_ago: This is a Media Library specific variable that contains a
    

    Nit: need a hyphen between "Library", and "specific", e.g. "Media Library-specific".

  25. +++ b/core/modules/media_library/tests/src/FunctionalJavascript/MediaLibraryTest.php
    @@ -0,0 +1,86 @@
    +  public function testAdministrationPage() {
    +    // Visit the administration page.
    +    $this->drupalGet('admin/content/media');
    +
    +    // Verify that media from two separate types is present.
    +    $this->assertSession()->pageTextContains('media_1');
    +    $this->assertSession()->pageTextContains('media_3');
    +
    +    // Test that users can filter by type.
    +    $this->getSession()->getPage()->selectFieldOption('Media type', 'Type One');
    +    $this->getSession()->getPage()->pressButton('Apply Filters');
    +    $this->assertSession()->assertWaitOnAjaxRequest();
    +    $this->assertSession()->pageTextContains('media_2');
    +    $this->assertSession()->pageTextNotContains('media_4');
    +    $this->getSession()->getPage()->selectFieldOption('Media type', 'Type Two');
    +    $this->getSession()->getPage()->pressButton('Apply Filters');
    +    $this->assertSession()->assertWaitOnAjaxRequest();
    +    $this->assertSession()->pageTextNotContains('media_2');
    +    $this->assertSession()->pageTextContains('media_4');
    +
    +    // Test that selecting elements as a part of bulk operations works.
    +    $this->getSession()->getPage()->selectFieldOption('Media type', '- Any -');
    +    $this->getSession()->getPage()->pressButton('Apply Filters');
    +    $this->assertSession()->assertWaitOnAjaxRequest();
    +    $this->getSession()->executeScript('jQuery(".media-library-item").click()');
    +    $this->submitForm([], 'Apply to selected items');
    +    $this->assertSession()->pageTextContains('media_1');
    +  }
    

    Let's call assertSession() once at the top of the method and keep re-using the result of that.

    Also, can we definitively assert that thumbnails are being displayed and names are not? Additionally, let's assert that bulk actions are present and functioning as expected.

samuel.mortenson’s picture

And from the UX meeting feedback:

  1. The media library introduces a few new UX patterns in core. That means it needs extra scrutiny from the UX, accessibility, and design teams.
  2. We'll need to sort their feedback into must-haves (major things that should block commit of this patch), and polish (which we can file major follow-up issues for and incorporate into the Media Initiative's roadmap).
  3. The media library should incorporate some standard "empty text" when there are no items to display.
  4. It is very jarring for the bulk actions to only appear when items are selected. Although it's not very pretty, let's just show the actions at all times (they should automatically disappear if the view is empty). Fixing the look n' feel of Views-provided filters and actions is beyond the scope of this patch, and there is prior art concerning that problem space, so we can punt on that for now.
  5. It's not clear how to distinguish between published and unpublished media items in the media library. This needs design input.
  6. One accessibility thing we should do is ensure that users can tab between the items in the library, press a key (space?) to select them, and hit another key (enter?) to visit them.
  7. There is no visual indication that a media item is supposed to be clicked on. One idea is to have an empty circle in the top right of each item, which is filled in with a checkmark when the item is clicked on. The only problem there is that an empty circle may not be visible with certain images, due to low contrast. This is another problem that needs design input, in order to ensure that the "selection target" is foolproof, visually speaking.
  8. The right-pointing chevron is weird -- it connotes a link to another page, rather than expanding or collapsing the item's metadata. Again, we need design input on this. One existing core pattern we could adopt is how the admin toolbar looks when it’s laid out vertically — collapsible sections use downward-pointing chevrons when they are collapsed, and upward-pointing chevrons when they are expanded.
  9. It's not clear if the metadata should expand downward (below the thumbnail), or upward (covering the thumbnail). This needs design and UX input.
  10. The media library has no drop buttons for editing or deleting media items. This is basically a regression compared to the current state of things. How can we integrate drop button actions into the media library? Should we even try? UX and design input is needed here.
  11. How will we support site builders displaying additional metadata? Do we even plan to support that? If so, will it be part of the collapsible metadata for each item? If it will be, what happens if they stuff a lot of metadata in there? This needs UX input.
  12. We might want to allow users to toggle between the media library grid, and the old table-based list. This is definitely a follow-up, though.

Status: Needs review » Needs work

The last submitted patch, 2: 2962110-1.patch, failed testing. View results

ckrina’s picture

Issue summary: View changes
FileSize
56.82 KB

I think the most important things would be:
- Empty text
- Bulk operations visible from the beginning and solve it in another issue.
- Agree on that the right chevron is not the appropriate pattern. Bottom/top chevron to follow admin toolbar pattern would be the ideal so we reuse patterns, but also html detail default visualization or +/- symbols.
- Accessibility: navigation&selection with keyboard. Is there any standard pattern?
- Editing & deleting media imho is really important. What about showing the "edit" and "delete" icons only when you're over an item? Like this Wordpress example. If we add the "check" on the right and the "edit"+"delete" icons on the left (or the opposite) I think it might be enough. Update: Just realized that we have bulk operations and the checkbox, so the actions can actually be done anyway.

- Expandable details upwards can be dangerous because it is really easy to have long names exceeding the height.
- I really liked the idea of having the selection pattern reusable!

So the needed designs might be:
- Bottom/top chevron
- Edit&delete buttons
- Checkbox (empty circle to indicate it's clickable)
- How to handle large amount of metadata: modal or new page?

phenaproxima’s picture

Issue tags: +Needs design

Tagging for design changes per #5.

phenaproxima’s picture

Issue tags: +Needs followup

From #3:

We might want to allow users to toggle between the media library grid, and the old table-based list. This is definitely a follow-up, though.

Let's open a follow-up issue for this request.

phenaproxima’s picture

Responding to #6:

So the needed designs might be...

Don't forget the ability to distinguish between published and unpublished media items. :)

How to handle large amount of metadata: modal or new page?

Would a tooltip be appropriate or useful for this?

samuel.mortenson’s picture

Status: Needs work » Needs review
FileSize
46.62 KB
15.7 KB

Responding to review from #2, no UX feedback addressed yet.

  1. Still waiting for UX feedback, but not all icons have every color available I think.
  2. Done - "media-library-item" is still used for styling but the "click-to-select" class now encapsulates all Javascript functionality for clicking something in a container and having a checkbox in that container checked/unchecked. See interdiff for more details.
  3. This plugin is the standard bulk form field generated by views, we cannot change the name of it (and don't need to, I think). The click to select stuff from this interdiff is generic enough to work with anything in views that ouputs a checkbox.
  4. Done
  5. The "media-library-item-content" class isn't used for any JS functionality, just styling. A generic class for the clickable-thing for click to select has been added, however.
  6. Will be addressed in UX review
  7. This dependency was auto-calculated, we shouldn't manually edit it.
  8. This dependency was auto-calculated, we shouldn't manually edit it.
  9. This dependency was auto-calculated, we shouldn't manually edit it.
  10. This dependency was auto-calculated, we shouldn't manually edit it.
  11. I feel like if we wanted to port this to Views, a better way would be to create a Views style plugin with configuration. A magic class that adds three lines of CSS seems like something not many people would use.
  12. Other parts of core use pixel font sizes, but if we're not supposed to I can change it.
  13. Tests added, done.
  14. Done.
  15. I removed this section of code as UX review showed the show/hide behavior of the bulk operations to be confusing.
  16. Comment removed.
  17. Done.
  18. Done.
  19. We depend on user because our View has a dependency on user - I think it's because we restrict view access based on user permissions, but I'm not sure. It's added automatically.
  20. Remove the jquery dependency, thanks.
  21. Added more test coverage for the "Add media" link.
  22. Marked as @internal, thanks.
  23. I went with Attribute objects, so that theme developers don't have to remember the class/data attribute names and we can make changes to them without breaking themes.
  24. Done.
  25. Done.

Also, can we definitively assert that thumbnails are being displayed and names are not?

We don't enforce that anywhere - since the view mode is configurable site builders are welcome to change what the preview looks like based on their use case.

Additionally, let's assert that bulk actions are present and functioning as expected.

We already have this test coverage, from what I can tell.

Status: Needs review » Needs work

The last submitted patch, 9: 2962110-9.patch, failed testing. View results

samuel.mortenson’s picture

Status: Needs work » Needs review
FileSize
46.51 KB
658 bytes

My debug code strikes again!

samuel.mortenson’s picture

FileSize
1.06 KB
46.52 KB

View config changes didn't get into the last patch.

samuel.mortenson’s picture

FileSize
46.91 KB
5.68 KB

We're blocked on design for the items in #5, but this patch introduces keyboard accessibility for the Media Library that appears to work pretty well. When you first tab into an item it has the same outline as a normal mouse hover, and pressing space (like you would press for a normal checkbox) selects it. If you tab again it focuses on the link to the Media item, which can be navigated to by pressing enter. This makes visiting an item and selecting it distinct, which I think it important and maybe more clear than having space/enter do different things on the same focused element.

phenaproxima’s picture

Nice work! I think we will want accessibility review for that.

phenaproxima’s picture

Status: Needs review » Needs work

We're making excellent progress. Great teamwork from everybody! I'm really looking forward to landing this.

I agree that we're mostly blocked on design, but true to form I was still able to raise questions and find some things we can spruce up. :)

  1. +++ b/core/modules/media_library/config/install/views.view.media_library.yml
    @@ -0,0 +1,418 @@
    +        description: 'Allows users to administer Media'
    

    Let's expand this a bit. How about "Allows users to browse and administer media assets."?

  2. +++ b/core/modules/media_library/js/media_library.view.es6.js
    @@ -0,0 +1,55 @@
    +  Drupal.behaviors.MediaLibraryCheckboxes = {
    

    Let's extract this into its own separate library and JavaScript file, so we can easily merge it into Views later (or at least let developers reuse it for things that aren't the media library). To keep things consistent, let's rename the behavior to something like viewsClickToSelect.

  3. +++ b/core/modules/media_library/js/media_library.view.es6.js
    @@ -0,0 +1,55 @@
    +          const $input = $(this).closest('.click-to-select').find('.click-to-select-checkbox input');
    

    Is it possible/easy to put the click-to-select-checkbox class directly on the checkbox, rather than having Yet Another Wrapper Element?

  4. +++ b/core/modules/media_library/js/media_library.view.es6.js
    @@ -0,0 +1,55 @@
    +      $('.media-library-item-attributes', context).after('<span class="media-library-item-toggle"></span>');
    

    Let's use $(context).find() here. I wonder if a <button> element would be more semantically correct here. Also, should the metadata toggling element have a title attribute, or some sort of text (suppressed with CSS) to indicate to screen readers etc. that it reveals metadata?

  5. +++ b/core/modules/media_library/js/media_library.view.es6.js
    @@ -0,0 +1,55 @@
    +      $('.media-library-item .media-library-item-preview', context).once('media-library-item').on('mouseover focus', function () {
    +        $(this).closest('.media-library-item').addClass('is-hover');
    +      }).on('mouseout blur', function () {
    +        $(this).closest('.media-library-item').removeClass('is-hover');
    +      });
    

    Let's use $(context).find() here too. Also, for readability, can we put the chained .once() and .on() calls onto their own lines?

  6. +++ b/core/modules/media_library/media_library.install
    @@ -0,0 +1,35 @@
    +  // Disable the /admin/content view provided by media, so that we can properly
    

    The path should be /admin/content/media. :)

  7. +++ b/core/modules/media_library/media_library.install
    @@ -0,0 +1,35 @@
    +    $display = &$view->getDisplay('media_page_list');
    

    It's possible that a site builder will have deleted the media_page_list display. We should probably check for that.

  8. +++ b/core/modules/media_library/media_library.install
    @@ -0,0 +1,35 @@
    +  // Restore the /admin/content view provided by media.
    

    Should be /admin/content/media.

  9. +++ b/core/modules/media_library/media_library.install
    @@ -0,0 +1,35 @@
    +    $display = &$view->getDisplay('media_page_list');
    

    Let's also sanity check for the presence of the media_page_list view here.

  10. +++ b/core/modules/media_library/media_library.module
    @@ -0,0 +1,94 @@
    + * @todo Write online documentation for the Media library and update the link.
    

    We probably don't need to do this in order to land an experimental module, but we should open a follow-up for this and link to it here.

  11. +++ b/core/modules/media_library/media_library.module
    @@ -0,0 +1,94 @@
    +      $output .= '<p>' . t('The Media library module overrides the /admin/content/media to provide a rich visual interface for performing administrative operations on media. For more information, see the <a href=":media">online documentation for the Media library module</a>.', [':media' => 'https://www.drupal.org/docs/8/core/modules/media']) . '</p>';
    

    Should be "...overrides the /admin/content/media view..."

  12. +++ b/core/modules/media_library/media_library.module
    @@ -0,0 +1,94 @@
    +    $variables['preview_attributes'] = new Attribute();
    +    $variables['preview_attributes']->addClass('media-library-item-preview', 'click-to-select-trigger');
    +    $variables['preview_attributes']->setAttribute('tabindex', 0);
    

    Doesn't this mean that all the items will, by default, have tabindex="0"? Could that produce unexpected behavior? I'm not sure there's any way for us to test that, but if there is, we should. (Maybe we could take advantage of the shiny new Nightwatch testing system for this, if you're up for it.)

  13. +++ b/core/modules/media_library/media_library.module
    @@ -0,0 +1,94 @@
    +  // Show formatted time differences for edits younger than a month.
    

    Can we make that threshold configurable? Maybe just introduce a hidden config setting for it.

  14. +++ b/core/modules/media_library/media_library.module
    @@ -0,0 +1,94 @@
    +    $date = date('m/d/Y - h:i A', $time);
    

    Rather than hard-code the date format, let's ship a DateFormat entity and use that (see https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Datetime%...).

  15. +++ b/core/modules/media_library/templates/media--media-library.html.twig
    @@ -0,0 +1,50 @@
    +      <div class="media-library-item-name">
    +        <a href="{{ url }}" rel="bookmark">{{ name }}</a>
    +      </div>
    +      <div class="media-library-item-created">{{ created_ago }}</div>
    +      <div class="media-library-item-type">{{ media.bundle()|title }}</div>
    

    It feels a little clumsy to keep repeating the 'media-library-item' prefix. Could we just add the media-library-item class to the <article> tag, then use classes like 'created' and 'type' for the created time and media type? And could we use a semantic <time> element for the created time? I'm not sure if these ideas constitute best front-end practice, though, so maybe a front-end dev should sign off on these first. Not a big deal either way. (Just 'cause we *could* doesn't necessarily mean we *should*, after all!)

  16. +++ b/core/modules/media_library/tests/src/FunctionalJavascript/MediaLibraryTest.php
    @@ -0,0 +1,98 @@
    +    $this->submitForm([], 'Apply to selected items');
    +    $assert_session->pageTextContains('media_1');
    +    $assert_session->pageTextNotContains('media_2');
    

    I assume this is testing that bulk actions work, by deleting one of the created media items. Just to be clear about that, let's explicitly select the delete action before clicking "Apply to selected items".

starshaped’s picture

Looking at item 15 in comment #15, I'd keep the media-library-item prefix on all the items. If we're following BEM or a BEM-ish convention, we'd want to name the classes more like media-library-item__name, media-library-item__created, and so forth. Even if Drupal 8 doesn't follow BEM conventions for naming CSS classes, it looks cleaner to target a single class rather than start making longer selectors which increase specificity.

samuel.mortenson’s picture

Status: Needs work » Needs review
FileSize
49.23 KB
16.5 KB

Addressing #15 -

  1. Done.
  2. Done.
  3. Because this is Drupal, no, we can't easily add classes to the actual input element. Easier to add them to the wrapper and let themes decide how they're used.
  4. $(selector, context) internally uses $(context).find(selector), so changing it is not necessary. See http://api.jquery.com/jquery/#selector-context. I added more accessibility attributes to the span element, which should be a large improvement. The toggled state and label are now visible.
  5. See above comment about context. I moved the calls to their own line.
  6. Done.
  7. Added a check. The interface for getDisplay says it always returns an array so I used empty() there.
  8. Done.
  9. Done.
  10. I need to make this follow up, and the follow up for the Twig pretty time still.
  11. Done.
  12. Yes, all items will have tabindex="0", which should be fine. Not sure about testing but it seems like overkill for this.
  13. Making the threshold configurable would require new config, schema, documentation, menu links, and forms, which is not desirable as we're trying to keep this patch simple. Themes and preprocess hooks can freely change the format of the outputted time. The only reason we use relative time is because it matched the original mockups, but if that's not desirable or intuitive we should remove it completely.
  14. Done. Added a new date format for the media library.
  15. I moved to BEM classes per #16 (thanks @starshaped!). We can't really use generic class names ever, because it may conflict with existing themes.
  16. Added more test coverage.
phenaproxima’s picture

This code is clean. I can't find anything else to nitpick. So, in order, here's what we still need to do in order to land the patch:

  1. We need design feedback from the UX team, and we need to implement that. I think we can get some expert assistance with the styling if needed.
  2. After that, we'll need CSS review, then and official sign-off from the UX and accessibility teams.
  3. It'd be nice to get sign-off from a JavaScript maintainer.
  4. We need to open a follow-up to move the "pretty time" functionality into Twig. Done: #2964790: Move formatting code in TimestampAgoFormatter into DateFormatter
  5. We also need to open a follow-up to move "click to select" functionality into Views.
  6. We need to post screenshots (possibly a screencast) and have a sorcerer of breaking things (I'm thinking @webchick) test it.
  7. Buy a six-pack of your favorite beer and wait for this to be committed.

Status: Needs review » Needs work

The last submitted patch, 17: 2962110-17.patch, failed testing. View results

samuel.mortenson’s picture

Issue summary: View changes
Status: Needs work » Needs review
FileSize
49.27 KB
1.25 KB

Fixed tests and created follow up issues. Also updated the IS with issue credits from the original MVP issue.

samuel.mortenson’s picture

Assigned: Unassigned » samuel.mortenson
ckrina’s picture

FileSize
176.18 KB

Here's a proposal for the design trying to adapt it to Seven styles, based on proposals from @yoroy, @dennis-cohn and @rfmarcelino in the #ux Slack channel:
- Example with audio, docs, images and video.
- Example with non-squared images.
- Example of hover&selected.
- Example of unpublished items.

Some accessibility concerns mentioned in the #ux slack channel by @andrewmacpherson and @benjifisher addressed here:
- Checkbox always visible.
- No caps.
- No important actions reserved for only hover.

Design proposal for media

Since we can use flexbox to have the same the height on items in the same line, having multiple lines per title makes sense. Anyway, I would try to limit the title's height/length to 4 lines or so with CSS so the grid keeps being readable.

samuel.mortenson’s picture

Thanks @ckrina (et. all)!

I have some notes/questions about the design:

1. If I make the "Checkbox always visible" per the design, should I style it with CSS to match the design as well? Checkboxes in Seven are basically unstyled right now, but the mockup looks nice. Actually increasing the default checkbox width seems to accomplish this nicely. I can remove the tabindex as well since accessible users can check the real checkbox themselves now.
2. The design doesn't contain the collapsible section for attributes. Is there a reason for this? Edit: Since the only attribute displayed in the collapsable area now is the created time, I'm going to remove the attributes completely. The area wasn't configurable in the user interface anyway so it would be hard for people to add more stuff here.
3. In the bottom middle item, the title is being hovered but the entire media item has an outline. When the title is clicked, the user will visit the media item, not select the checkbox, as it's an outgoing link (an A tag). I think that the outline should only be present if clicking will select the media item, which is how the behavior currently works.

samuel.mortenson’s picture

Issue tags: -Needs screenshots, -Needs design, -Needs followup
FileSize
48.24 KB
16.67 KB
372.8 KB

Media library update per UX review

Here's an update that addresses the mockup and feedback from #22 (the UX team).

I ended up removing the collapsible attributes area as it wasn't easily configurable, and after implementing the mockup only contained one piece of additional information. If users want more attributes displayed, they can simply add fields to the View.

I also added more options for the sort exposed filter - only one option was previously available which didn't make sense to expose.

dawehner’s picture

I applied the patch locally and really enjoyed seeing it!

Here is some quick review.

  1. +++ b/core/modules/media_library/config/install/core.date_format.media_library.yml
    @@ -0,0 +1,10 @@
    +pattern: 'm/d/Y - h:i A'
    

    I just compared this with our existing 'short' date format: 'm/d/Y - H:i' Is there a good reason to switch to AM/PM in the media library?

  2. +++ b/core/modules/media_library/js/media_library.click_to_select.es6.js
    @@ -0,0 +1,28 @@
    +      $('.click-to-select .click-to-select-trigger', context).once('click-to-select').on('click', function (event) {
    

    Note: There is quite a bit of code in Drupal which switched from classes to data attributes to do this kind of feature flagging. This way there are less problems when changing the markup.

samuel.mortenson’s picture

@dawehner Ah I should have removed core.date_format.media_library.yml, in #24 I removed the relative created date as it wasn't in the mockups from #22.

The main negative of switching to data attributes for this is that right now you can enable click to select with only the Views UI, which is how the library adds the right classes to make it work. If we moved to data attributes, you would always need to write template or preprocess code to add the attributes in the right place, and adding them to specific Views fields would not be pretty.

EDIT: Actually the .click-to-select-trigger class is added in a preprocess hook, so we aren't exclusively using the Views UI. I'll see how hard moving to data attributes would be.

samuel.mortenson’s picture

Issue summary: View changes

Updating issue credits to include UX team.

samuel.mortenson’s picture

FileSize
375.09 KB
47.9 KB
1.53 KB

Media library screenshot

Made a few tweaks to match the design better - notably always underlining the title and fixing some spacing/border issues.

I looked into using data attributes per #25.2, but I think the functionality is more useful if we use classes, as classes are easily added in Views which is what site builders would use to add this to other administrative interfaces. If we moved to data attributes you would need multiple preprocess hooks for every area you want to use this.

phenaproxima’s picture

@samuel.mortenson just demoed this patch in the UX meeting. @andrewmcpherson was there as well, and was able to offer accessibility input. Therefore, I'm removing the tag.

Summary of the feedback from that call:

  • This is looking excellent and everyone is very pleased with the progress being made!
  • The bulk selection checkboxes have a label which simply says "Update this item". This poses an accessibility problem because each item is wrapped by a div tag, which is not a semantic group, and therefore it's not clear to assistive technology what "this item" means. A couple of options were discussed, and the preferred solution is to change the label, which is visually hidden anyway, to "Update '$title_of_item'". Ideally, this pattern would be used for all views which use bulk selection, but that is a much bigger issue and very much out of the Media Initiative's scope. We've opened a follow-up to discuss fixing this everywhere: #2969660: Improve accessibility of bulk selection forms
  • There is a "sort by" filter on the media library, and the default option is "Newest first", but the actual items don't have any date or time-related information (as per #26). It's not clear if, and how, we should add it back. Or if we should talk about that/do it in a follow-up.
  • It would greatly improve the visual and user experience if the "Apply filters" and "Apply to selected items" buttons were displayed inline.
  • This is a problem we've inherited from Views, and therefore not in scope to fix here, but it's jarring that "Delete media" is the first bulk operation that is shown. Action weights should be configurable by users. Is there already an issue open to fix this? If not, we might want to open one.
  • If you have Content Moderation installed, and you're using it on media items, the published/unpublished status is next to useless. There's only so much we can do here in the short term (we can certainly make the relevant CSS styles easier to repurpose), but this may need more thought and work, for which I have opened #2969678: Integrate Media Library with Content Moderation
webchick’s picture

Yep to all of that. Here's the video for anyone who wants to see this patch in action and learn some cool things about accessibility! :) https://www.youtube.com/watch?v=L1Zh6YiQPIU

The only correction is I would say sorting by "Newest first" is the default expectation... you certainly would not want to see the same image of your dog you uploaded back in 2008 every single time you loaded this screen, and most likely the things added most recently are those you'd want to reuse. So we might need to keep that selection there so you can revert back to it after playing with the sort filter to be something else and then being all "nah."

I think the main point raised during the call was "should we also include a 'time ago' on the media element somehow so people can see how recent their picture is" and while we could, a) it's hard to cram much more data into that small "descriptive" area without it overtaking the thumbnail, and b) I noticed that Facebook, WordPress, and SquareSpace also have no exposed time ago field despite sorting recent first. (In fact they have no descriptive section at all—purely the visuals, so we're an outlier there...)

andrewmacpherson’s picture

Something I just noticed - there's no bulk-operations checkbox for selecting ALL media items. On the table displays there's a select-all checkbox in the table header, but we don't have that on this new display. Is that by-design, or a regression we overlooked?

phenaproxima’s picture

Only nitpicks, and very few at that. Code is RTBC from me otherwise, although I'd still like CSS review.

  1. +++ b/core/modules/media_library/js/media_library.click_to_select.es6.js
    @@ -0,0 +1,28 @@
    +        $input.prop('checked', !$input.prop('checked'));
    +        $input.trigger('change');
    

    Nit: These can be chained, I think. $input.prop('checked', !$input.prop('checked')).trigger('change')

  2. +++ b/core/modules/media_library/js/media_library.view.es6.js
    @@ -0,0 +1,24 @@
    +      const $preview = $('.media-library-item .media-library-item__preview', context).once('media-library-item');
    +      $preview.on('mouseover focus', function () {
    +        $(this).closest('.media-library-item').addClass('is-hover');
    +      });
    +      $preview.on('mouseout blur', function () {
    +        $(this).closest('.media-library-item').removeClass('is-hover');
    +      });
    

    Nit: We don't need the $preview variable if we chain the calls like .once(...).on('mouseover focus')...on('mouseout blur')

samuel.mortenson’s picture

@andrewmacpherson That's a regression - although I'm not sure why it's tied to tables specifically. May have to be something we fix in Views.

phenaproxima’s picture

Status: Needs review » Needs work

Kicking back until we have answers on #31 and #33.

GrandmaGlassesRopeMan’s picture

Issue tags: +JavaScript
  1. +++ b/core/modules/media_library/js/media_library.click_to_select.es6.js
    @@ -0,0 +1,28 @@
    +(function ($, Drupal) {
    

    This iife should get adjusted,

    (function ($, Drupal) {
      
    }(jQuery, Drupal))
    
  2. +++ b/core/modules/media_library/js/media_library.click_to_select.es6.js
    @@ -0,0 +1,28 @@
    +  "use strict";
    

    Two things, use single quotes, and we also don't need use-strict anymore.

  3. +++ b/core/modules/media_library/js/media_library.click_to_select.es6.js
    @@ -0,0 +1,28 @@
    +    attach: function (context) {
    

    Use the object-shorthand style for this function.

  4. +++ b/core/modules/media_library/js/media_library.click_to_select.es6.js
    @@ -0,0 +1,28 @@
    +      $('.click-to-select .click-to-select-trigger', context).once('click-to-select').on('click', function (event) {
    

    While just a warning, this is an unnamed function. You can use an arrow (preferred), or name it.

    Additionally, it would be a bit nicer to namespace these `once` events a bit more.

  5. +++ b/core/modules/media_library/js/media_library.click_to_select.es6.js
    @@ -0,0 +1,28 @@
    +      $('.click-to-select .click-to-select-checkbox input', context).once('click-to-select').on('change', function (event) {
    

    While just a warning, this is an unnamed function. You can use an arrow (preferred), or name it.

  6. +++ b/core/modules/media_library/js/media_library.click_to_select.es6.js
    @@ -0,0 +1,28 @@
    +    }
    

    Missing trailing comma.

  7. +++ b/core/modules/media_library/js/media_library.view.es6.js
    @@ -0,0 +1,24 @@
    +(function ($, Drupal) {
    

    This iife should get adjusted,

    (function ($, Drupal) {
      
    }(jQuery, Drupal))
    
  8. +++ b/core/modules/media_library/js/media_library.view.es6.js
    @@ -0,0 +1,24 @@
    +  "use strict";
    

    Two things, use single quotes, and we also don't need use-strict anymore.

  9. +++ b/core/modules/media_library/js/media_library.view.es6.js
    @@ -0,0 +1,24 @@
    +    attach: function (context) {
    

    Use the object-shorthand style for this function.

  10. +++ b/core/modules/media_library/js/media_library.view.es6.js
    @@ -0,0 +1,24 @@
    +      $preview.on('mouseover focus', function () {
    

    While just a warning, this is an unnamed function. You can use an arrow (preferred), or name it.

  11. +++ b/core/modules/media_library/js/media_library.view.es6.js
    @@ -0,0 +1,24 @@
    +      $preview.on('mouseout blur', function () {
    

    While just a warning, this is an unnamed function. You can use an arrow (preferred), or name it.

  12. +++ b/core/modules/media_library/js/media_library.view.es6.js
    @@ -0,0 +1,24 @@
    +    }
    

    Missing a trailing comma here.

GrandmaGlassesRopeMan’s picture

- fixes all my own JS feedback from #35

samuel.mortenson’s picture

Status: Needs work » Needs review
FileSize
51.65 KB
8.95 KB

This patch addresses the following accessibility/UX concerns:

  1. Form actions and now rendered inline, making the total height of the page much smaller.
  2. On focus, the media item name now has a full-border based on mockups @andrewmacpherson worked on.
  3. A select all checkbox has been added above the media item grid.
  4. The bulk operation labels now also contain the media item name, to address concerns about losing context of what is being operated on.
  5. Mobile styles have been updated so smaller screen sizes can still display items in a row.

Both notes from #32 have also been addressed.

andrewmacpherson’s picture

Review of patch #37

  1. There's a layout problem on Edge, Firefox and IE11. The grid of media items doesn't clear to the left after the bulk operations controls. Chrome doesn't have this problem. More cross-browser testing needed. This screenshot is from Edge:
    Screenshot of grid layout bug on media library.  The specimen media items are photos of parrots, in all the colours.
  2. + $form['media_bulk_form'][$key]['#title'] = t('Update media "@label"', [
    Remove the quote marks from the text here, because some screen readers might pronounce them. Narrator and NVDA were fine, but ChromeVox said "Update media quote red parrot quote", which is pretty ugly. If we think some kind of punctuation is necessary here, I'd go for a colon, so reads like "Update media colon Red parrot". Personally though, I don't think any punctuation is necessary here at all (in English).
    We could wrap the entity label in emphasis tags, like we do with on the permissions page for the various content type permissions, but screen readers don't generally treat this as any different from normal text, and this is an invisible label so the typography doesn't matter.
  3. + $form['media_bulk_form'][$key]['#title'] = t('Update media "@label"', [
    We can probably loose the word "media" too (to reduce verbosity) because media is the whole purpose of this page, and every item in the view is a media entity.
  4. The select-all checkbox is worded "select..." but the checkboxes for individual items are worded "Update...". We have this discrepancy on the node and user listings too, but I never noticed it until now. I have a feeling this might be confusing, because checking the box doesn't actually cause an update to happen - you're just picking some items for now, and nothing gets updated until the bulk-ops button is pressed. Not sure whether to worry about this or not.
  5. +.media-library-item__name a {
    +  text-decoration: underline;
    +  border: 2px solid transparent;
    +}
    +
    +.media-library-item__name a:focus {
    +  border-color: #40b6ff;
    +}
    

    This has an interesting severe side effect - it breaks when a Windows' high-contrast theme is being used. Beware of toggling colour to/from transparent to indicate state. In Windows' high-contrast mode, border width and style are respected, but border colour is overridden. CSS "transparent" is treated as a colour in this regard, so it results in ALL of the title links getting a visible border, whether they have focus or not.
    Screenshot of links, with a Windows high-contrast theme.  All links have a border drawn around them.

    I'd say this approach of toggling a border between transparent and blue fails WCAG 2.0 Use of color. The solution is to toggle the presence of the border, rather than the colour (i.e. toggle between 0px and 2px width). If this messes with the box model, you can use the CSS outline-* properties instead. An outline-offset: 0.15em is nice for readability.

    (Aside: core themes have lots of other problems in Windows high-contrast mode. I want to fix them in other issues. But we can avoid introducing new problems here.)

  6. +.media-library-item__name a:focus {
    +  border-color: #40b6ff;
    +}
    

    The blue is too pale. It has a contrast of 2.44 against the white background. There's a new WCAG 2.1 success criterion, 1.4.11 Non-text Contrast, which means we want a focus outline with 3:1 contrast. The easy solution would be to make the focus outline the same colour as the link text.

  7. The border used for focus also gets broken when it wraps to two lines. Treating the title as a block level element would make it neater.
  8. There's some kind of overflow problem with the focus borders, and the containing div. The top and left borders don't appear.

Leaving at needs review, I haven't looked at anything else in the patch.

andrewmacpherson’s picture

Something I mentioned in the UX meeting, but it hasn't been written down here yet...

The entity operations (dropbutton) links are have the same problem as the bulk operations checkbox - users need to know which media item they apply to. Just like bulk-ops checkbox, the dropbuttons currently get context from the HTML table row structure. But in the new grid, the dropbutton is outside of the rendered entity's <article> wrapper.

There's already an issue to address this in EntityListBuilder, but the dropbuttons in the new media library actually come from the EntityOperations views field plugin.

Between the bulk-ops checkbox, dropbutton links, and the visible title link, repeating the entity label stacks up to a lot of verbosity for screen readers. I'll have a think about this, and look around for other patterns, but for now I think we'll have to include the entity label in the operations links.

samuel.mortenson’s picture

FileSize
1.53 KB
51.67 KB
1.25 KB

This patch addresses #38:

1. Layout problem was fixed by setting a non-inline display for the select all media checkbox.
2/3/4. I updated the label to be "Select %label", which I think addresses all your points.
5. I took your advice I added the border on focus, instead of changing the color.
6. I've removed the border color which means it will default to the text of the font ("color").
7. I changed the name's display to block per your suggestion.
8. From my testing the changes in 6/7 fixed the overflow issue.

After researching #39, it appears to not be possible to alter the output of the entity operations field. So I think we have three options:

  1. Patch views to always have the label of the entity in the label of the operation (hidden or otherwise) for all instances of the entity operations field.
  2. Remove our label alter for the bulk operations checkbox and instead have the top-level grid element be more contextual. Not sure if that means changing the tag from "div" to "article" or something more intensive.
  3. Extend the Entity Operations field and add our custom labels there.
starshaped’s picture

I took a quick look at the CSS and it looks great to me!

Two minor comments:

  1. +++ b/core/modules/media_library/css/media_library.css
    @@ -0,0 +1,184 @@
    +  align-content: space-between;
    

    Does this have any effect on the grid of media items? space-between should add an equal amount of spacing between all the items in the grid, and I don't see that being applied. If this isn't needed, this can be removed.

  2. +++ b/core/modules/media_library/css/media_library.css
    @@ -0,0 +1,184 @@
    +  margin-right: 0.5em;
    

    I've noticed a mix of em and px for margin and padding values. I'd probably stick with one or the other, though there isn't any particular convention I can find for what units to use within Drupal. So, this is more of a 'keep things consistent' suggestion :)

samuel.mortenson’s picture

Thanks @starshaped - you're right that "align-content" was there in error, so I removed it. I also converted all "em" values to pixel values for consistency.

samuel.mortenson’s picture

Adding the "Needs frontend framework manager review" tag as we haven't had one yet.

samuel.mortenson’s picture

FileSize
52.05 KB
7.78 KB

I had talked to @lauriii in a PM and he had noted that the CSS isn't split up into functional/theme styles, so I did that in advance of the review.

andrewmacpherson’s picture

Accessibility review of patch #44, what's improved since #38

  1. The bulk-operations checkboxes for each media item have distinct labels. FIXED. Here's a screenshot of NVDA screen reader's form item's list. We see checkboxes called "Select Rainbow lorrikeet". "Select "Blue and Yellow macaws" as checkbox labels. I use parrot photos for all my test files.
    Screenshot of NVDA forms fields list.  Bulk operations checkboxes have distinct labels for each media item.
  2. The windows-high contrast bug with the focus outline is fixed. We're no longer toggling a border from transparent to blue, instead we're swapping a 2px margin for a 2px blue border. The screenshot shows a focus indicator for one media item title only. FIXED, very nice indeed.
    Screenshot of links, with a Windows high-contrast theme.  One media item title is focused, and shows an outline.
andrewmacpherson’s picture

Continuing accessibility review of patch #44, stuff not fixed since #38...

The Entity Operations drop button has repeated buttons and links which aren't contextually tied to the individual media items. When we had a table view, these dripbuttons were inside the same row TR wrapper, so context could be inferred by exploring the row.

With three media items, we see three indistinguishable "Edit" links. Here's a screenshot of NVDA's list-links tool.
Screenshot of NVDA list-links tool.  Three links are all called edit.

Similarly, there are 3 indistinguishable "list additional actions" buttons, in NVDAs list-buttons tool.
Screenshot of NVDA list-buttons tool.  3 buttons are all called list additional actions.

I think we are best of fixing this in EntityOperations itself, providing some flexible display options for the output.

phenaproxima’s picture

Issue tags: -Needs followup, -JavaScript

Opened #2973124: Provide better context in accessible names of EntityOperation views plugin drop-button operations to address #39 and #46. And with that, all requested follow-ups have been opened and I believe accessibility review is complete.

phenaproxima’s picture

Status: Needs review » Needs work
FileSize
16.56 KB
17.62 KB

Demoed this in the UX call using simplytest.me. There were (only!) three excellent pieces of feedback:

  • When thumbnails are broken, as in the attached screenshot, the alt text is just "Thumbnail", which is bad from an accessibility standpoint. Can we fix that? If not, let's open a follow-up to fix it. I'm not sure this is a commit blocker, but think it is a stability blocker.
  • When no thumbnail exists for a media item, the generic icon is too big compared to the design in #22 (see the attached screenshot). Can we reduce them in size, in this view only? If not, let's open a follow-up.
  • The "select all media" action makes sense as a checkbox when it's in a table, but it doesn't make as much sense in a grid of thumbnails. Although she is on the fence about it, @ckrina suggested making it a button (which is fine from an accessibility standpoint, according to @andrewmcpherson). So we need a touch of design input on this, but for now we should go ahead and make it a button rather than a checkbox, if possible.
samuel.mortenson’s picture

Addressing #48:

1. The "Media library" view mode's preview area (just the thumbnail, by default) is output by core's entity/field API. If thumbnails have this problem here, they have this problem everywhere media thumbnails are displayed. Long story short - the Media library doesn't set this and can't change the default behavior. This alt text is set in \Drupal\media\Entity\Media::updateThumbnail, where it also looks like the default title text is set to the entity label. Looking at test coverage for Media it looks like this is expected behavior, and is unrelated to what the library is doing.
2. The original size of the icons is 180x180px, so we would have to conditionally restrict the size of thumbnails if a media icon was being displayed, which is not possible with the current Media API. We're outputting the thumbnail in a view mode, and trust the source plugin to give us something that represents the media and looks presentable.
3. I'll work on making this a button.

EDIT: #2 may be possible by using another image style for audio/video/file and changing some CSS. Will look into it.

andrewmacpherson’s picture

Re #48.1, I found #2956368: MediaThumbnailFormatter produces unhelpful text alternative and title attributes for media thumbnails which claims alt="Thumbnail" is by design for MediaThumbnailFormatter. I've reclassed it as a major bug. I guess it could be a stability blocker for Media Library, but the formatter is already in use by the table version of the media listing.

samuel.mortenson’s picture

This patch fixes #48.2 by changing the image style to "thumbnail" for non-Image types by default, and ensuring that the CSS doesn't upsize small images which it was previously doing.

I started converting the select all checkbox to a button but it didn't feel right - with the checkbox the on/off (toggle) state is clear, but with a button we would need to change the button text every click. It also seemed like a button should go into the bulk form, not floating around on the screen. It would be good to have designs on this if the checkbox isn't desirable, before we move over to a different HTML element.

andrewmacpherson’s picture

For accessibility, things are going well so far, and we have some follow-ups which are fairly well understood. No concerns from me for committing this as an experimental module.

ckrina’s picture

Issue summary: View changes
FileSize
110.49 KB

Yesterday in the ux call we discussed whether to use a button for the “Select all” instead of a select. The main reason is that it’s not a single item to be picked, it's an action. Actually, it’ll override the other selects in the grid, so unless we come up with a better visual way to explain the hierarchy (like happens in the table) a button is a much simpler way to imply it.

But there’s yet another problem to solve once you have all items selected (as @samuel.mortenson said):
- The select all button looses it’s purpose and it’d be confusing to keep it when all items are selected.
- What if you want to “unselect all”?

So I would add a button that toggles between "select all" and "unselect all"(not a copy specialist here :P) as it is clicked/has done its job. The ideal design would be implementing designs from #2721807: Design for filters and bulk operations.

But since it is out of scope from this issue I'd go for something like this:

ckrina’s picture

Issue summary: View changes
FileSize
267.65 KB

Sorry, uploaded the wrong file.

samuel.mortenson’s picture

Thanks @ckrina - the button looks a lot more natural inline with the rest of the form.

dddbbb’s picture

Also not a copy specialist but "Unselect all" should probably be "Deselect all".

John Pitcairn’s picture

Or perhaps "Select none"?

samuel.mortenson’s picture

FileSize
53.22 KB
4.77 KB

This patch moves the "Select all" checkbox to a button per the mockups in #53. I went with "Deselect all" but the other text, and added an "aria-pressed" attribute to assist with accessibility.

I didn't move the "Apply to selected items" button to the right as it feels wrong on larger screen sizes. I think it's OK to wait for all Views to do this in #2721807: Design for filters and bulk operations. It may seem odd to users to have one view where this is out of its normal place.

andrewmacpherson’s picture

+ const $button = $('<a class="button media-library-select-all" aria-pressed="false"></a>')
This isn't keyboard operable. Use a <button>

What's the aria-pressed for? Only use that for a button which behaves like a toggle. Also, it doesn't make sense on a HTML <a> element - links don't toggle.

andrewmacpherson’s picture

"Select all" vs "Deselect all" isn't actually a toggle behaviour. They are two separate actions, to override the selections made in the grid of individual items, which could be in a mixed state.

Let's imagine there are 20 items shown. 7 are selected, 13 not selected. In this state, both actions would make sense. So it isn't appropriate to treat the button as a boolean toggle (aria-pressed=true|false).

This is actually more like a tri-state switch, where you cycle though mixed/all/none. Desktop applications use them, but they're not very common on the web. Now aria-pressed and aria-checked both support tri-state widgets - in the ARIA rec, at least. I haven't looked at how well supported that is in real tech. Come to think of it, the select-all checkbox on the table display would benefit from this too. ARIA wasn't around in Drupal 3 or whenever the bulk operations appeared ;-)

"Invert selection" would be a toggle behaviour. Some Linux file managers have that.
MacOS Finder only has "select all", it doesn't have "deselect-all", or "invert selection".

andrewmacpherson’s picture

Tagging, I'm a bit concerned about this button.

samuel.mortenson’s picture

@andrewmacpherson I tried using aria-pressed after reading through https://inclusive-components.design/toggle-button/, but agree that it should probably be a button element as it is in that article.

What path forward would you suggest for the "Select all" functionality? Is moving to a button adequate, or should we go back to the checkbox? I don't want to re-roll the patch until we have UX and accessibility team agreement on what should be implemented.

andrewmacpherson’s picture

Status: Needs review » Needs work
Issue tags: -Needs accessibility review

I've been thinking more about the select-all checkbox, to avoid complicating things...

  • Let's not bother with the tri-state button idea for now. I've filed #2974944: Use a tri-state checkbox for tableselect widget. as a nice generic feature we could have eventually.
  • Also let's not use aria-pressed=true|false in a boolean way. Unless we fully implement the tri-state behaviour, it could be misleading.
    Edit: by coincidence, I found some relevant advice just a few hours later...
    if your actual label text changes when toggling, aria-pressed is likely not necessary (could actually be more confusing for user)

    Source: Patrick Lauke, WAI-ARIA - An introduction to Accessible Rich Internet Applications (slide 104).

  • Instead, just update the action text on the button, and convey the outcomes to assistive tech using Drupal.announce() for now. So we'd have announcements which said "All 20 items selected" and "Zero items selected".

With this in mind, that means I prefer a <button> to a checkbox.

GrandmaGlassesRopeMan’s picture

  1. +++ b/core/modules/media_library/js/media_library.click_to_select.es6.js
    @@ -0,0 +1,27 @@
    +          $(event.currentTarget).closest('.click-to-select').toggleClass('checked', $(event.currentTarget).prop('checked'));
    

    Personal preference, but this line feels a bit too long. Maybe two or more chained methods we wrap them?

  2. +++ b/core/modules/media_library/js/media_library.click_to_select.es6.js
    @@ -0,0 +1,27 @@
    +        .on('change', (event) => {
    

    We have destructured event elsewhere. I think it makes sense to do it here.

  3. +++ b/core/modules/media_library/js/media_library.view.es6.js
    @@ -0,0 +1,46 @@
    +        $('.media-library-view .view-content [id*="edit-header"] .form-actions').prepend($button)
    

    Missing a semicolon here.

  4. +++ b/core/modules/media_library/tests/src/FunctionalJavascript/MediaLibraryTest.php
    @@ -0,0 +1,102 @@
    diff --git a/sites/README.txt b/sites/README.txt
    
    diff --git a/sites/README.txt b/sites/README.txt
    old mode 100644
    new mode 100755
    diff --git a/sites/default/default.services.yml b/sites/default/default.services.yml
    
    diff --git a/sites/default/default.services.yml b/sites/default/default.services.yml
    old mode 100644
    new mode 100755
    diff --git a/sites/default/default.settings.php b/sites/default/default.settings.php
    
    diff --git a/sites/default/default.settings.php b/sites/default/default.settings.php
    old mode 100644
    new mode 100755
    diff --git a/sites/development.services.yml b/sites/development.services.yml
    
    diff --git a/sites/development.services.yml b/sites/development.services.yml
    old mode 100644
    new mode 100755
    diff --git a/sites/example.settings.local.php b/sites/example.settings.local.php
    
    diff --git a/sites/example.settings.local.php b/sites/example.settings.local.php
    old mode 100644
    new mode 100755
    diff --git a/sites/example.sites.php b/sites/example.sites.php
    
    diff --git a/sites/example.sites.php b/sites/example.sites.php
    old mode 100644
    new mode 100755
    

    Are we sure we want to adjust the permissions on these files?

samuel.mortenson’s picture

Status: Needs work » Needs review
FileSize
52.28 KB
11.12 KB

Thanks for the review!

This patch addresses #63 and #64, and also removes some selector nesting for BEM-style classes we have.

Two pieces of UX feedback from chat and the meeting on Tuesday have also been addressed:

1. Clicking the Media item name now takes you to the edit form, if you have permission. From our discussions it seems like the most common action from the library is to edit media, not view it in its full view mode.
2. The Entity Operations dropdown has been removed from each Media item in the grid. The only operations for Media were "Edit" and "Delete", both of which are possible by either clicking the Media item name or using the bulk operations. This was done with the caveat that the table view will also be available for users who want more metadata and operations displayed. @andrewmacpherson and others have already brought this up a few times as well. :-)

For (2), I have not been able to implement a good-looking switcher between the table and grid views yet, but am still working on it.

ckrina’s picture

Issue summary: View changes
FileSize
195.42 KB

As discussed in the #ux channel, here's the last proposal for the design:

1. Adds new table/grid switch buttons so the content can be adapted to each one needs.
2. Proposes to remove the media type label as @samuel.mortenson mentioned in the previous comment.
3. Proposes to show one line of media name by default, then show the rest on hover. There wasn't an agreement on the last UX, so this decision still needs accessibility review at least.
4. Changes styling of the attribute area.
5. Moves the checkbox to the top right, and the unpublished status to the left.

samuel.mortenson’s picture

FileSize
53.5 KB
4.66 KB
319.19 KB

This patch addresses some of the UX feedback from #66:

1. Instead of table/grid switch buttons, local tasks are added as sub-tabs to switch between the new and old Media view. We discussed this in chat and agreed that buttons may be confusing as they are just links to other View pages, and the current selection and exposed filter values will not carry over to the next page. Users know what to expect when clicking local tasks.
2. The media type label has been removed.
3/4. The attribute styling and hover behavior has not been changed yet. It's not a lot of CSS but I wanted to wait until the next UX meeting to decide on the hover behavior, then I'll do the attribute styling.
5. The checkbox/unpublished label have been swapped.

Here's a new screenshot from this patch for reference:

Media library progress as of May 25th 2018

andrewmacpherson’s picture

Patch #67:

+  Drupal.behaviors.MediaLibraryHover = {
+    attach(context) {
+      $('.media-library-item .media-library-item__preview', context).once('media-library-item')
+        .on('mouseover focus', ({ currentTarget }) => {
+          $(currentTarget).closest('.media-library-item').addClass('is-hover');
+        })
+        .on('mouseout blur', ({ currentTarget }) => {
+          $(currentTarget).closest('.media-library-item').removeClass('is-hover');
+        });
+    },
+  };

Focus and blur events will never fire on .media-library-item__preview because it isn't a focusable element - it's just a wrapper DIV. If we want to provide the blue border is-hover style for keyboard users, we'd want something like:

/* Needs a :focus-within polyfill for IE11 and Edge */
.media-library-item:focus-within {}

or

+  Drupal.behaviors.MediaLibraryFocus = {
+    attach(context) {
         // :tabbable selector comes from jQuery UI
+      $('.media-library-item .media-library-item__preview :tabbable', context).once('media-library-item-focus')
+        .on(focus', ({ currentTarget }) => {
+          $(currentTarget).closest('.media-library-item').addClass('has-focus-within');
+        })
+        .on('blur', ({ currentTarget }) => {
+          $(currentTarget).closest('.media-library-item').removeClass('has-focus-within');
+        });
+    },
+  };
andrewmacpherson’s picture

More review of patch #67:

I tested the Drupal.announce() messages from the select-all button. They're good.

Re: #66.3

3. Proposes to show one line of media name by default, then show the rest on hover. There wasn't an agreement on the last UX, so this decision still needs accessibility review at least.

It would be good to show the full title to keyboard users as they are tabbing though items. A complication is that the hover area contains TWO focusable items for a keyboard user - the checkbox and the title. When a mouse user sees the whole title on hover, it helps them to decide which checkboxes to select. For a keyboard user to have a comparable experience, they would need to see the full title when the checkbox has focus, not just when the title has focus. This is a bit like a tooltip behaviour.

So we'd want something like:

.media-library-item__preview.is-hover .title,
.media-library-item:focus-witihin .title {
  /* styles to show the full title when focus is on a checkbox OR a title link */
}

.media-libary-item__preview .title:focus
{
  /* Indicate the title has focus.  This needs to be in addition to the full-title display.
}
.media-libary-item__preview [type="checkbox"]:focus
{
  /* Indicate the checkbox has focus
}

I mentioned this in Slack, just saying it again here.

andrewmacpherson’s picture

We should remove the image title attributes - they're no use. Only mouse users can perceive them, and it just duplicates visible text nearby:

  • On the table view, the thumbnail image column is followed by the title column, which shows the entire title.
  • On the grid view, the truncated title is visible, and the full title will be visible on :hover and :focus-within.

I think this might be an issue with the media thumbnail formatter in general, so maybe not in scope here.

Aside: Drupal core makes way too much use of title attributes in all sorts of places where they are useless, so it might be better to address this in a "stop using unncessary title attributes" plan for the whole of core.

andrewmacpherson’s picture

The blue is-hover border appears when you hover over a preview image, but it dssappears when you hover over the checkbox itself.

andrewmacpherson’s picture

We're just using the user-agent focus styles for the checkboxes. Nothing wrong with that, but we've provided our own focus style for the title link, so it feels a bit half-done to still use the user-agent style for the checkboxes. More consistency would make it easier to follow focus visually.

samuel.mortenson’s picture

@andrewmacpherson For #68, I thought that the checkbox would be what keyboard users interact with, which is why it's tabbable and the entire Media item is not.

andrewmacpherson’s picture

@samuel.mortenson My point in #68 is that
on(mouseover focus) creates a JS focus event listener which will never fire, so it shouldn"t be there.

The tabbing order itself is correct - checkbox and link are both focusable - and I wasn't proposing to change that.

Rather, I mean that whatever styling is supposed to be activated by on(mouseover focus) will actually only work for mouseover. I think the border around the whole media item could help keyboard users too, but it would need to track focus-within, because the wrapper isn't focussable.

The focus indicators for the checkboxes and title links must remain tough.

Does this make sense? I could make a little demo.

samuel.mortenson’s picture

Thanks @andrewmacpherson, that makes sense. The "focus" listener is left over from when the item itself was tab-focusable. I'll address that in the next patch.

Edit: Looked into the image title attribute - that's not set by the Media library so it's not something we can change here. Will address feedback about revealing the entire title when the checkbox or title is focused once we get UX feedback.

yoroy’s picture

Issue summary: View changes
FileSize
139.12 KB

I'm not a big fan of on hover solutions. I think we designed this explicitly to create as much room for longer titles as possible. Then again, grid layouts like this will eventually break if we don't take ultra-super-long titles and/or long words like Eisenbahnenschienenhinundhersteller into account. So maybe we need some kind of mechanism to handle overflow anyway.

Still, I'd like to proceed with what I see in #67

The "Select all" button seems to be in a weird place. Was a "Select all" checkbox on top of the grid itself considered?

samuel.mortenson’s picture

@yoroy We limit the height of Media titles, which was requested in earlier mockups. The mockup you uploaded is very close to how the checkbox looked before we moved to a button - it appeared right above the grid.

andrewmacpherson’s picture

For expanding the full title, we can make that work for hover, and focus too.

What about touch screen users? I don't see how they will expand the truncated title.

ckrina’s picture

Issue summary: View changes
FileSize
250.41 KB

During Frontend United @yoroy and I discussed and agreed in the following design:
- Change from dark background to white for the item title to play better with Seven general styles.
- Revert the "Select all" to a select again.
- Don't move the "Apply to selected items".
- Title is a link, cropped by default and expanded when hovering it.

samuel.mortenson’s picture

@andrewmacpherson Could we have your feedback on #79? You mentioned in #63 that you prefer a button to a checkbox, if we go back to a checkbox (similar to what you previously reviewed) would that break accessibility?

samuel.mortenson’s picture

This patch implements the mockup from #79, and addressed:

#68 - The unused (unusable?) blur and focus event listeners have been removed.
#69 - I added a is-focus class to the ".media-library-item" element if the checkbox is focused. If the media item is focused, the full title is displayed.
#71 - Using the is-focus class, the blue border is visible when the checkbox is being focused and hovered.
#72 - The above change should address the inconsistency with checkbox interactions (keyboard and mouse).
#78 - The full title is shown on focus, but I have not implemented anything for touch users yet.

I'd like UX feedback on how we should show full titles to touch users, @andrewmacpherson mentioned in chat that he would like to see this addressed.

yoroy’s picture

Maybe the touch interaction can both select the item and show the full title? My assumption here is that in those cases that the selected item is not what you were looking for *based on reviewing the full title* it will be quicker to just unselect that item.

samuel.mortenson’s picture

@yoroy So when you touch the media item to select it (by touching the thumbnail or checkbox), that shows the full title. If you just touch the truncated title it visits the link normally. Is that right? Would you expect the full title to be displayed for selected items on desktop as well?

ckrina’s picture

About keeping same behaviour on desktop... I'm not sure there's a reliable way to differentiate from touch screens so I'd keep it consistent and I'd try to keep the same interaction for now. So it means having the full title displayed for selected items in desktops too.

webchick’s picture

Soooo... just to remind folks that we're trying to put this feature into core as an Experimental module, at least initially. So while all the attention to these details/edge cases, balancing UX vs. accessibility concerns, etc. is greatly appreciated, I'm concerned that we might be endangering the feasibility of this making it into 8.6 at all if we don't get something committed sooner than later.

Are we close here, or should we start spinning off sub-issues for some of these gnarlier bits?

webchick’s picture

Priority: Normal » Major

Also, escalating this to "Major" since it is both one of the main roadmap items for this initiative, and also blocks other aspects of it, e.g. inserting media during content creation.

samuel.mortenson’s picture

Thanks for the clarification @ckrina - I think this can be accomplished by showing the media name when the item is checked, which is the change I made here. This is ready for review.

phenaproxima’s picture

Status: Needs review » Reviewed & tested by the community

Only minor nits. None should block commit.

  1. +++ b/core/modules/media_library/css/media_library.module.css
    @@ -0,0 +1,56 @@
    +.media-library-view .view-content [id*="edit-header"] > div,
    +.media-library-view .form--inline {
    +  display: flex;
    +  flex-wrap: wrap;
    +}
    

    We can combine this with the .media-library-view .view-content form selector.

  2. +++ b/core/modules/media_library/css/media_library.module.css
    @@ -0,0 +1,56 @@
    +.media-library-view .view-content [id*="edit-header"] {
    +  flex-basis: 100%;
    +}
    

    Let's combine this with the .media-library-view .view-content form > [id*="edit-actions"] selector.

  3. +++ b/core/modules/media_library/js/media_library.view.es6.js
    @@ -0,0 +1,68 @@
    +      $('.media-library-item .media-library-item__preview,.media-library-item .click-to-select-checkbox', context).once('media-library-item-hover')
    

    Nit: We should add a space after the comma separating the selectors. Also, can the .once() call be moved to its own line?

  4. +++ b/core/modules/media_library/js/media_library.view.es6.js
    @@ -0,0 +1,68 @@
    +      $('.media-library-item .click-to-select-checkbox input', context).once('media-library-item-focus')
    

    Nit: Can .once() be on its own line?

I echo @webchick's sentiment from #85. The bikeshed has been open for a long time on this issue, which is a very important 8.6 target. We need to land this thing. It has undergone a lot of UX and accessibility review, and at this point we don't seem to have any commit-blocking problems on either front, although we've generated several follow-ups (many of which address deficiencies we are inheriting from other parts of core). Everyone seems pretty happy with the patterns we're implementing here. The code looks good to me, and I would certainly consider its new APIs (which is really just the "click to select" stuff) to be beta-quality, although this module is mostly configuration and therefore should not need an update path if we change it later, seeing as how it is an experimental module.

We have beaten around the bush long enough. It's time to go to RTBC.

lauriii’s picture

Status: Reviewed & tested by the community » Needs work

I reviewed the front-end parts of the latest patch. Mostly it looks good, but there's few things we should still fix. Only the first of the issues should be commit blocking, so if you prefer to open follow-ups for rest of the feedback, feel free to do so.

  1. +++ b/core/modules/media_library/css/media_library.theme.css
    @@ -0,0 +1,149 @@
    +* @file media_library.theme.css
    

    These styles are quite opinionated so we should move them to Seven before we mark this module Stable. Let's add a @todo comment so that we don't forget that.

    We also have to make sure that the UI works without these styles.

  2. +++ b/core/modules/media_library/js/media_library.click_to_select.es6.js
    @@ -0,0 +1,31 @@
    +      $('.click-to-select .click-to-select-trigger', context)
    ...
    +            .closest('.click-to-select')
    +            .find('.click-to-select-checkbox input');
    ...
    +      $('.click-to-select .click-to-select-checkbox input', context)
    ...
    +            .closest('.click-to-select')
    
    +++ b/core/modules/media_library/js/media_library.view.es6.js
    @@ -0,0 +1,68 @@
    +      $('.media-library-item .media-library-item__preview,.media-library-item .click-to-select-checkbox', context).once('media-library-item-hover')
    ...
    +          $(currentTarget).closest('.media-library-item').addClass('is-hover');
    ...
    +          $(currentTarget).closest('.media-library-item').removeClass('is-hover');
    ...
    +      $('.media-library-item .click-to-select-checkbox input', context).once('media-library-item-focus')
    ...
    +        $(currentTarget).closest('.media-library-item').addClass('is-focus');
    ...
    +        $(currentTarget).closest('.media-library-item').removeClass('is-focus');
    ...
    +      const $view = $('.media-library-view', context).once('media-library-select-all');
    +      if ($view.length && $view.find('.media-library-item').length) {
    ...
    +              .closest('.media-library-view')
    +              .find('.media-library-item input[type="checkbox"]');
    ...
    +        $view.find('.media-library-item').first().before($label);
    

    We should prefix the classes used in JavaScript with js-. While moving to js- prefixed classes, it would be good idea to revisit the selectors to make sure that we use good specificity, for example .media-library-item .media-library-item__preview selector doesn't need .media-library-item because BEM already guarantees that .media-library-item__preview is inside .media-library-item.

  3. +++ b/core/modules/media_library/css/media_library.module.css
    @@ -0,0 +1,56 @@
    +.media-library-view .view-content form > [id*="edit-actions"] {
    ...
    +.media-library-view .view-content [id*="edit-header"] > div,
    ...
    +.media-library-view .view-content [id*="edit-header"] {
    

    Could we add a class instead of using the id for theming?

  4. +++ b/core/modules/media_library/css/media_library.module.css
    @@ -0,0 +1,56 @@
    +.media-library-view .view-content form {
    

    Would it be possible to add class to the form element to simplify this selector?

samuel.mortenson’s picture

Status: Needs work » Needs review
FileSize
54.63 KB
11.04 KB

Thanks for the review @lauriii! I think I addressed all your feedback from #89:

1. Added a @todo. Also commented out the theme CSS temporarily and the library was mostly functional, I just added one new style to ensure that the checkbox is positioned relative to the media item.
2. I prefixed the selectors with js-, and audited the JS/CSS to see where I could remove parent selectors. I think this should look better now.
3. We luckily already had a form alter that I could use to add classes for this, so this is done now.
4. A new class is used here as well.

chr.fritsch’s picture

Is there a reason why the media_library view mode of image is using the medium image style and all the other media types are using the thumbnail image style?

chr.fritsch’s picture

Ah, I think I can answer my question by myself :)
Image is the only media type that supports "real" thumbnails. The others are using the default icon, and for that one, the thumbnail image style is enough.

phenaproxima’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: -Needs frontend framework manager review

Now that @lauriii has reviewed this, we can remove the front-end framework manager review beacon.

The changes look good to me. I'm moving it back to RTBC, and hopefully we can get a chance to run this past committers soon.

lauriii’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/modules/media_library/css/media_library.theme.css
@@ -0,0 +1,150 @@
+ * @todo Move into the Stable theme when this module is marked as stable.

Sorry, bumping back to NW. We actually want to move this to Seven because we don't want to include this in Stable. If we don't move this to Seven, we cannot make any changes to these styles after marking the module Stable. Since these styles are quite opinionated, the UX team might want to make improvements to these in future.

phenaproxima’s picture

Issue tags: +Needs followup

Let's also open a follow-up for that, and link to it in the comment, so we don't forget.

samuel.mortenson’s picture

Status: Needs work » Needs review
Issue tags: -Needs followup
FileSize
54.69 KB
568 bytes

Sorry, misread the comment about moving the styles. I've fixed the @todo and opened #2980769: Move Media Library styles into the Seven theme now.

phenaproxima’s picture

Status: Needs review » Reviewed & tested by the community

Looks good. Thanks, Sam.

GrandmaGlassesRopeMan’s picture

Status: Reviewed & tested by the community » Needs work
  1. +++ b/core/modules/media_library/js/media_library.click_to_select.es6.js
    @@ -0,0 +1,31 @@
    +      $('.js-click-to-select__trigger', context)
    

    A number of places we've used $(context).find().

  2. +++ b/core/modules/media_library/js/media_library.click_to_select.es6.js
    @@ -0,0 +1,31 @@
    +        .once('click-to-select')
    

    These .once() keys should probably be prefixed with media library or something similar. Click-to-select feels vague.

  3. +++ b/core/modules/media_library/js/media_library.view.es6.js
    @@ -0,0 +1,68 @@
    + * @file media_library.view.js
    

    This should be .es6.js

  4. +++ b/core/modules/media_library/js/media_library.view.es6.js
    @@ -0,0 +1,68 @@
    +        .on('mouseover', ({ currentTarget }) => {
    +          $(currentTarget).closest('.media-library-item').addClass('is-hover');
    +        })
    +        .on('mouseout', ({ currentTarget }) => {
    +          $(currentTarget).closest('.media-library-item').removeClass('is-hover');
    +        });
    

    I think we can use the ability to pass multiple events and use .toggleClass() to simplify this.

  5. +++ b/core/modules/media_library/js/media_library.view.es6.js
    @@ -0,0 +1,68 @@
    +      .on('focus', ({ currentTarget }) => {
    +        $(currentTarget).closest('.media-library-item').addClass('is-focus');
    +      })
    +      .on('blur', ({ currentTarget }) => {
    +        $(currentTarget).closest('.media-library-item').removeClass('is-focus');
    +      });
    

    Looks like all of these lines have some incorrect indentation.

    Additionally,

    I think we can use the ability to pass multiple events and use .toggleClass() to simplify this.

  6. +++ b/core/modules/media_library/js/media_library.view.es6.js
    @@ -0,0 +1,68 @@
    +        const strings = {
    +          announce_selected: 'All @count items selected',
    +          announce_deselected: 'Zero items selected',
    +        };
    

    Bit curious why these strings are stored in an object when they are only used once.

phenaproxima’s picture

Discussed #98.2 with @drpal and to clarify -- we don't need to change the CSS class names; just the key we pass to .once().

samuel.mortenson’s picture

Status: Needs work » Needs review
FileSize
53.87 KB
8.06 KB

Addressing #98:

1. This was brought up in #15.4 and addressed in #17.4 - the current syntax internally calls .find() so the result should be identical, with less verbosity.
2-6. Fixed, thanks!

phenaproxima’s picture

Status: Needs review » Reviewed & tested by the community

The changes look good and @drpal's feedback has been addressed. Thanks!

webchick’s picture

Just reviewed this with @GáborHojtsy and @phenaproxima. This looks frigging AWESOME!!

Played around with various things, and here's a list of what was found:

The biggest thing is that when the module is enabled, you don't actually see the Media tab on the admin/content page until you click on one of the other tabs, or manually clear the cache. This is some sort of views caching issue, because the code in hook_install() is loading the view, replacing some properties, and then re-saving which you would think would be enough to clear the local cache, but sadly no. So we either need a follow-up or to identify the existing issue about this, if applicable. Because this is an upstream problem, however, not a commit blocker for this.

Minor, but the media tab lacks an empty table text the same as the other things under Content. We should add that for consistency.

The URL Alias + Revision/Author info fieldsets still appear which clutters up the form spectacularly. :( However, this is a "pre-existing" condition. There's also a magically shifting around published checkbox that's sometimes above and sometimes below the fieldsets, depending on the media type. Also, "pre-existing condition," though.

"Save" media (under the bulk actions) is a bit goofy; I can't think of any reason you'd want to do that from here. However, that's something that just came over from the existing page in core.

I'm also a little confused... Grid vs. table? Why do we still have both? Seems like a stable blocker to unify this, but not a blocker for beta.

The empty text thing would be great to fix before commit if possible, but not a commit-blocker.

Product manager sign-off: complete!

Because this is a new module for core, adding framework manager review, and because we're hoping it to be beta quality, adding release manager review as well.

phenaproxima’s picture

amateescu’s picture

  1. +++ b/core/modules/media_library/js/media_library.view.es6.js
    @@ -0,0 +1,58 @@
    +            const announcement = $(currentTarget).prop('checked') ? 'Zero items selected' : 'All @count items selected';
    +            Drupal.announce(Drupal.t(announcement, {
    

    l.d.o's parser does not know to look up variables like this, we need to pass the actual string to Drupal.t() otherwise it won't be translatable.

  2. +++ b/core/modules/media_library/media_library.install
    @@ -0,0 +1,49 @@
    +      $view->save();
    ...
    +      $view->save();
    

    We should probably call trustData() on the view before saving.

  3. +++ b/core/modules/media_library/media_library.module
    @@ -0,0 +1,109 @@
    +function media_library_preprocess_media(&$variables) {
    

    Can't we put this in the media--media-library twig template?

    I thought we were trying to get rid of preprocess hooks.

  4. +++ b/core/modules/media_library/media_library.module
    @@ -0,0 +1,109 @@
    + * @todo Remove in https://www.drupal.org/project/drupal/issues/2969660
    

    Minor nit: I think @todos are meant to be placed after @params.

GrandmaGlassesRopeMan’s picture

To fix #104.1

const announcement = $(currentTarget).prop('checked') ?
  Drupal.t('Zero items selected') :
  Drupal.t(`All ${$checkboxes.length} items selected`);
Drupal.announce(announcement);

xjm credited Dennis Cohn.

xjm credited DyanneNova.

xjm credited benjifisher.

xjm credited jan.stoeckler.

xjm credited rfmarcelino.

xjm credited seanB.

xjm credited webflo.

xjm’s picture

Status: Reviewed & tested by the community » Needs work

Marking NW for #104. :) Also adding issue credit for those listed in the summary and for other reviewers on the issue.

amateescu’s picture

Re #105: I think the Drupal.t(`All ${$checkboxes.length} items selected`); part from your proposed code should be Drupal.t(`All @count items selected`, { '@count': $checkboxes.length }); instead.

samuel.mortenson’s picture

Status: Needs work » Needs review
FileSize
54.04 KB
5.74 KB

Addressed #104 except for #3 - a preprocess hook is required because we need to add additional cache contexts and conditionally swap out a URL based on permissions, which is not possible in Twig. The attribute objects could be moved to Twig, but because the Javascript is reliant on those classes we didn't want templates to think they could not include them in an override.

I also ran into a bug with the new combined event handlers which I fixed by only adding classes when it's the right event.

For #102:

Minor, but the media tab lacks an empty table text the same as the other things under Content.

This table is provided by core media and is not altered by this patch. If we want to add empty table text we'd need to open a new issue and add an update hook since the View is already used on all sites using core media.

I'm also a little confused... Grid vs. table? Why do we still have both? Seems like a stable blocker to unify this, but not a blocker for beta.

From accessibility/UX review we found that the table is always going to be preferred for users using screen readers that can better parse table markup, and for more technical users that want to show more metadata than the Grid is able to nicely handle. We could make this configurable and only show the Grid by default on new installs in a follow up, if showing both isn't desirable.

phenaproxima’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +Needs followup

If we want to add empty table text we'd need to open a new issue and add an update hook since the View is already used on all sites using core media.

That's worth looking into. Let's open a follow-up for it.

We could make this configurable and only show the Grid by default on new installs in a follow up, if showing both isn't desirable.

Also a worthwhile discussion to have, but out of scope for this issue, so a follow-up is called for there.

The changes look good; all feedback since #102 has been addressed. Back to RTBC once it's green.

phenaproxima’s picture

webchick’s picture

We had a conversation today between a few folks, including @xjm, @samuel.mortenson, and @phenaproxima.

Due to the multiple upstream dependencies, as well as the lack of concrete design spec, #2938116: Allow media to be uploaded with the Media Library field widget looks unlikely to land in 8.6. The idea we discussed was shipping Media Library as beta in 8.6 if it includes both this issue and #2962525: Create a field widget for the Media library module. This might need more thinkering, but at a glance, this would give us the ability to ship something of significant value in D8.6 (select from existing media functionality), while giving us the ability to make the "upload new media" experience really slick.

plach’s picture

Overall this looks good to me, nothing blocking stood out. I also performed some manual testing and things looked good, nice work!

I have only once concern, but given this is experimental code I think it would be fine to address it in a follow-up:

+++ b/core/modules/media_library/media_library.install
@@ -0,0 +1,49 @@
+  if ($view = View::load('media')) {
+    $display = &$view->getDisplay('media_page_list');
+    if (!empty($display)) {
+      $display['display_options']['path'] = 'admin/content/media-table';
+      unset($display['display_options']['menu']);
...
+    if (!empty($display)) {
+      $display['display_options']['path'] = 'admin/content/media';
+      $display['display_options']['menu'] = [
+        'type' => 'tab',

This logic seems a bit fragile: it's assuming the original media library view was never customized, but that's not safe. I moved the view to another location, installed media_libray, uninstalled it, and my customization was reverted. We should probably add some checks to verify that the path and menu settings are the default ones before altering them.

phenaproxima’s picture

Opened #2981105: Media Library should not modify the media view in response to the above. Thanks, @plach!

catch’s picture

Status: Reviewed & tested by the community » Needs review
Issue tags: -Needs release manager review

This looks pretty good to me, I don't see a problem with it going in as an experimental module, except unless I'm missing something there's no access control on the view at the moment (see first point):

  1. +++ b/core/modules/media_library/config/install/views.view.media_library.yml
    @@ -0,0 +1,447 @@
    +  page:
    +    display_plugin: page
    +    id: page
    +    display_title: Page
    +    position: 1
    +    display_options:
    +      display_extenders: {  }
    +      path: admin/content/media
    +      menu:
    +        type: tab
    +        title: Media
    +        description: 'Allows users to browse and administer media items'
    +        expanded: false
    +        parent: system.admin_content
    +        weight: 5
    +        context: '0'
    +        menu_name: admin
    +    cache_metadata:
    +      max-age: 0
    +      contexts:
    +        - 'languages:language_interface'
    +        - url
    +        - url.query_args
    +        - 'url.query_args:sort_by'
    +        - user.permissions
    +      tags: {  }
    

    Isn't this missing access?

  2. +++ b/core/modules/media_library/media_library.install
    @@ -0,0 +1,49 @@
    +
    +/**
    + * Implements hook_install().
    + */
    +function media_library_install() {
    +  // Change the path to the original media view.
    +  /** @var \Drupal\views\Entity\View $view */
    +  if ($view = View::load('media')) {
    +    $display = &$view->getDisplay('media_page_list');
    +    if (!empty($display)) {
    +      $display['display_options']['path'] = 'admin/content/media-table';
    +      unset($display['display_options']['menu']);
    +      $view->trustData()->save();
    +    }
    +  }
    +}
    

    Are we ever going to replace this fully, or is this always going to be necessary? I'm wondering why we couldn't just hide the existing tab, add a new tab, and use a different path. Why do we need to use an identical path here? Could be changed in a follow-up but it feels odd.

phenaproxima’s picture

I'll leave @samuel.mortenson to respond to #121.1. As far as the second point goes, though -- realism aside, I think the ultimate long-term dream is to replace the table we currently have with the grid, since it's more "visual" and therefore more amenable to displaying a library of media assets. There are a lot of UX questions to sort out there, however, and a follow-up is already open at #2981105: Media Library should not modify the media view (I have copied @catch's feedback into that issue).

catch’s picture

Status: Needs review » Needs work

For example views.view.media.yml has this:

 display_options:
      access:
        type: perm
        options:
          perm: 'access media overview'

Marking CNW because I'm sure this is missing.

phenaproxima’s picture

Status: Needs work » Reviewed & tested by the community
FileSize
119.93 KB
130.11 KB

Tested locally with the patch in #115 and confirmed that the Media Library has the "access media overview" permission. Screenshot:

Media library view, with patch 115

And, for good measure, I confirmed that the modified Media view has the permission as well:

Media view, with patch 115

Everything looks to be in order, so I'm restoring RTBC.

catch’s picture

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

OK that's me sorry, it's right up the top of the view, I was looking for it in the page display :(

+++ b/core/modules/media_library/config/install/views.view.media_library.yml
@@ -0,0 +1,447 @@
+langcode: en
+status: true
+dependencies:
+  config:
+    - core.entity_view_mode.media.media_library
+  enforced:
+    module:
+      - media_library
+  module:
+    - media
+    - user
+id: media_library
+label: 'Media library'
+module: views
+description: ''
+tag: ''
+base_table: media_field_data
+base_field: mid
+core: 8.x
+display:
+  default:
+    display_plugin: default
+    id: default
+    display_title: Master
+    position: 0
+    display_options:
+      access:
+        type: perm
+        options:
+          perm: 'access media overview'

#2981105: Media Library should not modify the media view as a follow-up seems fine.

Given this has had product sign-off, both me and plach have reviewed it too, this seems fine to go in as experimental and it's good to see incremental steps towards reusable media widgets.

Fixed these DrupalCS issues before commit:

diff --git a/core/modules/media_library/css/media_library.theme.css b/core/modules/media_library/css/media_library.theme.css
index 783a17b3cc..0427143538 100644
--- a/core/modules/media_library/css/media_library.theme.css
+++ b/core/modules/media_library/css/media_library.theme.css
@@ -20,8 +20,8 @@
   border: 1px solid #ebebeb;
   margin: 16px 16px 2px 2px;
   width: 180px;
-  background: #ffffff;
-  transition: border-color .2s, color .2s, background .2s;
+  background: #fff;
+  transition: border-color 0.2s, color 0.2s, background 0.2s;
 }
 
 .media-library-view .form-actions {
@@ -70,7 +70,7 @@
 .media-library-item__status {
   color: #e4e4e4;
   font-style: italic;
-  background: #666666;
+  background: #666;
   padding: 5px 10px;
   font-size: 12px;

Committed d4350e2 and pushed to 8.6.x. Thanks!

  • catch committed d4350e2 on 8.6.x
    Issue #2962110 by samuel.mortenson, drpal, andrewmacpherson, ckrina,...
andrewmacpherson’s picture

Re: #115 (emphasis mine):

From accessibility/UX review we found that the table is always going to be preferred for users using screen readers that can better parse table markup, and for more technical users that want to show more metadata than the Grid is able to nicely handle. We could make this configurable and only show the Grid by default on new installs in a follow up, if showing both isn't desirable.

It's already configurable: site builders can disable the media table view.

I'm dead set against having the table view disabled on new installs. Of all the accessibility aspects looked at in this issue, keeping the table view is by far the biggest win. It's not just for screen reader users: it provides useful metadata for everyone, and offering multiple ways to manage things is a principle of inclusive design. If the table view was off by default, my hunch is that few site builders would ever think to turn it on for their users. If it's enabled by default, my hope is that few site builders will ever turn it off :-)

Edit: Other benefits of keeping the table view...

  • Doesn't have to to deal with truncated titles. Long titles get wrapped in their table cell, and make the row a bit row taller. The table design accommodates this easily.
  • Lets you see the full title, without obscuring the thumbnails.
  • Lets you see all titles in full, none truncated. The card grid just shows one expanded title at a time.
  • Has room for the entity operations links/dropbutton.
  • Easier for site builders to extend, allowing any columns known to Views. For example, license/rights, video length, a media tags field. The card grid can't accommodate much more information.

The choice of grid / list is quite common. A quick look at my phone apps show that Google Drive, Dropbox, the Android file manager, and my RSS reader all have a button to swap between a list and a card/grid view.

webchick’s picture

The choice of grid / list is quite common. A quick look at my phone apps show that Google Drive, Dropbox, the Android file manager, and my RSS reader all have a button to swap between a list and a card/grid view.

Cool, that data point is helpful. My review was less "let's get rid of that" and more "Hm. Why?" since it creates maintenance overhead to keep the two views in sync. But #127 is a pretty good wrap-up of why, so cool. :)

Status: Fixed » Closed (fixed)

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

xjm’s picture

Discussed with @catch. This is something we want to highlight in the frontpage post about the release. :) We don't think there's any specific update instructions we need to add for it though.

kiwad’s picture

Since its marked as an highlight, why removing it from 8.6-dev ?
https://github.com/drupal/drupal/commit/bd6756510075429ef539c5727461323e...

Christopher Riley’s picture

I would really hate to see this not be included in 8.6 as it will really be a step backward in getting media in a real usable form.

samuel.mortenson’s picture

@kiwad @christopher-riley This is a quirk of the Drupal 8 release cycle - because the Media Library's field widget (#2962525: Create a field widget for the Media library module) did not make it into 8.6 before the alpha 1 deadline, the module was removed form 8.6.x but remained in 8.7.x. Once the field widget is committed to 8.7.x, core maintainers can (and likely will) decide to backport it to 8.6.x before the beta deadline (which is next week).

This is the first new experimental module I've worked on so I also had to learn about release-cycle stuff. :-)

Mingsong’s picture

I am working on an installation profile in which the Media Library module is a required module via the info.yml.

For some reason, the media_library_install() wasn't called after installing the profile.

Is there anyone have seen an issue like this?

Mingsong’s picture

For anyone is facing the issue raised in #134,

The install hook function won't be called during a profile is being installed. If you create your custom installation profile in which the Media Library is enabled, you need to copy the 'views.view.media.yml' from '/core/modules/media/config/optional/' to your profile config/install folder and then make following changes:

      path: admin/content/media-table
      menu:
        type: none
Mingsong’s picture

FileSize
23.84 KB

Here is the patch to fix the issue with installation profile raised on #134

annerl’s picture

Thank you guys for the great work on Media Library!

So far, I'm missing just two features:

1. As a author, I'm in the backend on a node form with a media field. I see the media library preview of the inserted images. Now I want to change something about the inserted images (e.g. its crop settings). I propose a simple button next to the media item preview which links me to the media edit form.

2. Help test in Media Library insert dialogue for image field:
As a admin, I tried to put some help text for my clients under the image field in the insert dialogue. I changed the help text in the settings under
/admin/structure/media/manage/image/fields/media.image.field_media_image
But the entered text doesn't appear in the insert dialogue.

apaderno’s picture

@annerl This issue has been closed 2 years ago. If you have any feature request, it would be better to create a new issue.